我想用jQuery的$.ajax
函數上傳文件,但沒有得到任何輸出。 有人請幫我解決這個問題。 我不知道這個腳本是否正確。 我的腳本是:
$.ajax({
url:'newsup.php',
data: "",
type: 'POST',
contentType:'multipart/form-data',
dataType: 'json',
catche: 'false',
success:function(data6)
{
$("#disp").removeClass().addClass((data6.error=== false)? 'success':'error').html(data6.msg).fadeIn('fast');
//dele();
if($("#disp").hasClass('success'))
{
alert("success");
setTimeout("$('#disp').fadeOut('slow')",3000);
}
},
error:function(XMLHttpRequest,textStatus,errorThrown)
{
$("#disp").removeClass().addClass('error').html("There was an <strong>"+errorThrown+"</strong> error due to <strong>"+textStatus+" condition").fadeIn('fast');
}
});
此外,我需要幫助使用jQuery從文件上傳現場獲取數據。
查看plupload(http://www.plupload.com/)以獲取AJAX式表單上傳的示例。如果不使用嵌入式iframe來提交不可見的表單,則通過普通帖子在單個頁面中提交帶有文件的表單非常困難。 Plupload也很好地與jQuery集成(至少那是我的經驗)。 –
你有做過這方面的任何谷歌?我希望有很多有用的結果。其中一個http://www.phpletter.com/Demo/AjaxFileUpload-Demo/ –
如果你可以使用一個,https:// github,那麼有一個流行的和經過測試的jquery插件。com/blueimp/jQuery-File-Upload –