【发布时间】:2012-05-16 13:59:15
【问题描述】:
我正在尝试使用 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 (plupload.com) 以获取执行 AJAX 样式的表单上传的示例。如果不使用嵌入式 iframe 来提交不可见的表单,则通过单个页面中的普通帖子提交带有文件的表单是非常困难的。 Plupload 还与 jQuery 很好地集成(至少这是我的经验)。
-
你有没有为此做过谷歌?我希望会有很多有用的结果。其中之一phpletter.com/Demo/AjaxFileUpload-Demo
-
如果您可以使用的话,有一个流行且经过良好测试的 jquery 插件,github.com/blueimp/jQuery-File-Upload
-
抓到? ,它应该是“缓存”。可能是拼写错误?
-
我对使用任何插件都不感兴趣。我只想要一个通过 $.ajax 函数上传文件的最简单的解决方案。