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

标签 php jquery ajax json

我尝试使用 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”即可。

请阅读下面的示例
http://jquery.malsup.com/form/#ajaxForm

关于php - 如何使用 jquery 的 $.ajax 函数以及 json 和 php 上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10492617/

相关文章:

php - PHP 的 JQuery ajax post 问题

php - 如果表 A 中包含的值被删除,如何将表 B 值(包含表 A 中的值)更改为 0

javascript - 非 webkit rotateY 动画与 Jquery 的 Transform3d

javascript - Ajax表单提交页面重定向

php - 如何从脚本中获取当前的 PHP 可执行文件?

php - db_update drupal 7 问题

javascript - 无法更新

javascript - Php 计时器没有停止在 00 :00

javascript - 从 $.POST 返回值

jquery - 类型错误 : 'stepUp' called on an object that does not implement interface HTMLInputElement