douchun1948 2015-03-11 10:48
浏览 51
已采纳

Jquery序列化:没有从php中获取请求中的数据

I have the following function

function addProductNew(){
//       var upform = new FormData($('#contact_form')[0]);
//      var form = new FormData($('#contact_form1')[0]);
var data1 = $('#contact_form, #contact_form1').serialize();
            // Make the ajax call
            $.ajax({
                url: '../sa/addProduct.php',
                type: 'POST',
                xhr: function() {
                    var myXhr = $.ajaxSettings.xhr();
//                    if(myXhr.upload){
//                        myXhr.upload.addEventListener('progress',progress, false);
//                    }
                    return myXhr;
                },
                //add beforesend handler to validate or something
                //beforeSend: functionname,
                success: function (res) {
//                    $('#content_here_please').html(res);
                alert(res);
                },
                //add error handler for when a error occurs if you want!
                //error: errorfunction,
                data: data1,
                // this is the important stuf you need to overide the usual post behavior
                cache: false,
                contentType: false,
                processData: false
            });
}

Request Header
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:156
Content-Type:text/plain;charset=UTF-8
Cookie:user=John+Doe; SahilManchadna=John+Doe; PHPSESSID=55gafm230s53vvdn5kt5gjdh40; __atuvc=34%7C10; __atuvs=55000819d4240536012
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/dreamshop/admin/fragments/addproduct.php
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payload
productdomain=101&producttype=1001&productname=sahil&productdescription=manchanda&companynae=panthane&vendorid=1&size=1&color=5&quantity=q&price=qq&test=ddd
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive

on the server side

echo '<pre>';
print_r($_REQUEST);
echo '</pre>';

It is not getting any data from the request. However if I change the method type to GET then it is able to display the data. I have serialized two forms data using jquery. please help me

  • 写回答

1条回答 默认 最新

  • doukuilian8365 2015-03-11 12:24
    关注

    I found the mistake. the contentType was set to false when i changed it to contentType: 'application/x-www-form-urlencoded' it worked and i got the data from the request.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起