小编典典

我如何使用json和php使用jquery的$ .ajax函数上传文件

ajax

我正在尝试使用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从文件上传字段获取数据。


阅读 221

收藏
2020-07-26

共1个答案

小编典典

AJAX不支持文件上传。有些插件如ajaxfileupload基本上会创建一个隐藏的表单并动态上传文件。

2020-07-26