php请求的问题

时间:2014-05-28 11:13:20

标签: php ajax wamp

我创建了一个使用AJAX post方法请求信息的应用程序。信息已使用JSON格式编码并传递到我的PHP文件。在我的WAMP服务器上,它可以很好地工作,也适用于我在办公室的另一台专用服务器。我想把它放在另一台服务器(webhost24)上,但是当我通过ajax post请求发送数据时,PHP文件没有收到任何数据(返回默认值为0,数组中没有值)。

你能帮帮我吗?

修改

js文件

var uploadStatus = "uploading...";                      //Set value of status
Win('#popSync', 1);                                     //open dialog window
var JSONdepot = JSON.stringify(depots);                 //JSON stringify depots
var JSONcomm = JSON.stringify(Comm);                    //JSON stringify Comm
var JSONreport = JSON.stringify(report);                //JSON stringify report
var JSONevents = JSON.stringify(events);                //JSON stringify events
alert("This is JSON DEPOT: " + depots);
$('#loader').html('<img src="themes/images/301.gif">'); //Set ajax loader
$('#loaderHead').html('<h1>Events synchronizing</h1>'); //Provide header
$('#uploadStatus').html(uploadStatus);                  //set text to status of sync

        $.ajax({                                                                                                    //Ajax comand to connect pass information to syncdata.php file
            type: "POST",                                                                                           //Type: post
            url: "syncdata.php",                                                                                    //URL of file http://sersa.gmi.app should be included when building appliction
            data: {depot: JSONdepot, techname: techsname, comm: JSONcomm, report: JSONreport, events: JSONevents}   //pass depot, techsname, report, and events to url
        })
            .done(function(data){               //When completed
                $('#uploadStatus').html(data);
                if(data >0){                    //If data returns a number greater than zero

                setTimeout(function () {        //set time out of 2 seconds
                        $('#loaderHead').html('<h1>Events synchronized</h1>');          //Set header
                        $('#loader').html('<img src="themes/images/complete.png">');    //Change ajax loader to commpleted 'tick'
                        $('#uploadStatus').html(data + " events synchronized");         //provide how many events have been synced
                        CommRemove();                                                   //clear related information
                        DepotRemove();
                        CHNoRemove();
                        DeleteReportLocal();
                        depots = [];
                        Comm = [];
                        report = [];
                        tempComm = [];
                    }, 2000);
                }

            })
            .fail(function(){
                alert("Something went wrong.<br>ER: SY01");                                //If failed, provide message
            });

PHP文件

$depot =json_decode($_POST['depot']);      //Tried $_POST aswell... still same issue
$comm = json_decode($_REQUEST['comm']);    //$_REQUEST doesn't work.. turns out blank
$report = json_decode($_REQUEST['report']);
$events = json_decode($_REQUEST['events']);
$tech = $_REQUEST['techname'];
$depotLength=count($depot);                //Counts return 0
$commLength=count($comm);
$reportLength=count($report);
$eventLength=count($events);
echo "this is Depot: " . $depotLength;     //Returns 0

1 个答案:

答案 0 :(得分:0)

只需使用它来获取所有POST数据:

$postdata = file_get_contents("php://input");

然后解码它。

$json= json_decode($postdata,true);