0
如果我只是使用序列化的表单作为数据,我可以让它工作,但由于我试图包含上传文件,它也失败了,它什么也不做?苦于使用ajax文件上传
$(document).ready(function() {
$('#advice_submit').click(function(e){
var formData = new FormData($('form#ask_advice_form')[0]);
$.ajax({
url: 'ajax/ask_advice_ajax.php',
type:'POST',
data: formData,
dataType: 'json',
success: function(response){
$('#success').html(response.question_id+' '+response.user);
}, // End of success function of ajax form
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
}); // End of ajax call
});//close whole function
});//close whole function
形式
<form method="post" enctype="multipart/form-data" id="ask_advice_form">
<input type="text" id="desc" name="desc" maxlength="50">
<textarea name="advice_question" id="advice_question"></textarea>
<input type="file" name="file" id="image" style="border:none">
<input type="button" name="advice_submit" id="advice_submit" value=""
class="request_opinion white_submit" >
</form>
您确信您的代码是100%正确的? –
哪个代码?我知道ask_advice_ajax.php是正确的,因为ot与序列化的形式工作,我不相信jquery – tatty27
它是如何失败?服务器有错误吗? JavaScript控制台上的错误?当您将其与工作版本进行比较时,它生成的请求有什么不同? – David