Jquery 序列化:在 php 中不从请求中获取数据


Jquery Serialization: not getting data from the request in php

>我有以下函数

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

在服务器端

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

它不会从请求中获取任何数据。但是,如果我将方法类型更改为GET则它能够显示数据。我已经使用 jquery 序列化了两个表单数据。请帮助我

我发现了错误。 当我将其更改为contentType: 'application/x-www-form-urlencoded'它工作并从请求中获取数据时,contentType设置为false