简体   繁体   English

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

[英]ajax returns payload instead of form data

I return a payload instead of a form data and I can not retrieve the values ​​with php I need a post type formdata but I can not figure out how to 我返回的是有效载荷而不是表单数据,我无法使用php检索值,我需要一个post类型的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);              
        }
      });

 });

How can I do it? 我该怎么做?

This: 这个:

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

Is not a valid content type. 不是有效的内容类型。 Remove that line. 删除该行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM