我尝试使用 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 从文件上传字段获取数据。
最佳答案
请为此使用插件。
在我看来,这个插件是更好的解决方案。您不需要记住所有选项等。只需将“ajax”替换为“ajaxForm”即可。
关于php - 如何使用 jquery 的 $.ajax 函数以及 json 和 php 上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10492617/