我無法提交表單,因爲.query()在jquery中沒有被解僱。誰能幫我?這裏是我的代碼的一部分...('form')。submit()沒有啓動
<form id="repmsg" class="remember" method="post" action="test.php" enctype="multipart/form-data">
<input type="file" name="filepj" id="message_file" class="message_file f_left" style="float: left;"/>
<input type="submit" style="display: none" name="pj" id="pj1">
</form>
<a onclick="sendMessage(<?php echo $mId; ?>);" href="javascript:;" class="envoyer_reponse f_right"><?php echo $translate->translate('send'); ?><span><span></span></span></a>
<a onclick="cancelMessage(<?php echo $mId; ?>);" href="javascript:;" class="annuler_reponse f_right"><?php echo $translate->translate('wish_popup_annuler'); ?></a>
當我點擊鏈接sendMessage時,jquery函數被激發。這裏是的sendMessage()函數
function sendMessage(id) {
var mId = id;
if($('#msg_txt_'+id).val() != '') {
var message_file = $('#message_file').val();
uploads();
$.ajax({
type: 'post',
data: { mId: id, type: 1, message: $("#msg_txt_"+id).val(), act:"rep", msg_file : message_file},
url: path_relative_root+'message-detail.php',
success: function(response){
if(response == '1') {
$('#msg_conf_'+mId).html(message_send);
$('#msg_conf_'+mId).show();
}
else {
$('#msg_conf_'+mId).html(message_fail);
$('#msg_conf_'+mId).show();
}
}
});
}
else
$('#msg_conf_'+mId).hide();
}
從這個的sendMessage()函數,有這將對.submit()
function uploads(){
var message_file = $('#message_file').val();
console.log(message_file);
if(message_file != ''){
console.log('test');
$(document).ready(function() {
$("#repmsg").submit(function(e) {
e.preventDefault();
data = new FormData($("#repmsg")[0]);
console.log('Submitting');
alert('hello');
$.ajax({
type: 'POST',
url: path_relative_root + 'message-detail.php',
data: data,
cache: false,
contentType: false,
processData: false
}).done(function (data) {
console.log(data);
}).fail(function (jqXHR, status, errorThrown) {
console.log(errorThrown);
console.log(jqXHR.responseText);
console.log(jqXHR.status);
});
});
});
}
}
是否有人可以幫助我找到一個上傳()函數我錯誤,爲什麼我不能提交我的表格。謝謝
因爲'e.preventDefault'的? – vaso123
你從哪裏調用'uploads()'? –
我應該刪除e.preventDefault嗎? lolka_bolka –