ajax返回有效负载而不是表单数据

时间:2014-10-26 22:33:34

标签: javascript php jquery ajax forms

我返回有效负载而不是表单数据,我无法使用php检索值 我需要一个帖子类型formdata但我无法弄清楚如何

    $('#send_avatar').click(function(){

      var x=document.getElementById("x").value;
      var y=document.getElementById("y").value;
      var w=document.getElementById("w").value;
      var h=document.getElementById("h").value;

      var fd = new FormData();    

      //fd =  'x=' + x  + '&y=' + y + '&w=' + w  + '&h=' + h ;

      fd.append('file', $('#uploadImage')[0].files[0]);
      fd.append('x', x);
      fd.append('y', y);
      fd.append('w', w);
      fd.append('h', h);



        $(".ris").html("<img src='images/loading.gif' height='30px'>");        


      //dataString.append("image", immagine);

        $.ajax({
        type: "POST",
        url: "funzioni/upload_avatar.php",
        data: fd,   
        async: false,  
        cache: false,
        contentType: "X-Requested-With:XMLHttpRequest",
        processData: false,        
        success: function(response){
          $(".ris").html(response);              
        }
      });

 });

我该怎么做?

1 个答案:

答案 0 :(得分:1)

此:

contentType: "X-Requested-With:XMLHttpRequest",

不是有效的内容类型。删除该行。

相关问题