发布到php的Ajax对象不会被php看到


Ajax object posted to php is not seen by php

我要发送这个:

=

开关= rssAdd&数据对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象的对象,对象(对象)

由以下命令创建:

$(xml).find('item').each(function() {
    var stage = $(this).attr('p4:stage');
    var title = $(this).find('title').text();
    var desc = $(this).find('description').text();
    var location = $(this).find('category').eq(0).text();
    var billtype = $(this).find('category').eq(1).text();
    var linkurl = $(this).find('link').text();
    var thedate = $(this).find('a10'':updated,updated').text();
    thedate = thedate.substring(0,10);
    var todaydate = $.datepicker.formatDate('yyyy-mm-dd', new Date());
    //if(todaydate == thedate) {
    info.push({'stage': stage,'title': title,'description': desc,'location': location,'billtype': billtype,'linkurl': linkurl,'thedate': thedate});
    //}

});
console.log(info);
var senddata = json_encode(info);
$.ajax({
        url: 'php.php',
        type: 'POST',
        dataType: 'text',
        data: 'switch=rssAdd&data='+senddata,
        success: function(result) {
            //console.log('here is the result: ' + result);
        }
});

接收到php.php文件:

<?php
 header("Content-Type: application/json");
  include('sql.php');
  $switch = $_POST['switch'];
  switch ($switch) {
case "rssAdd":

    $info = json_decode($_POST['data']);
    print_r($info);

//  $sql = "INSERT INTO rssFeed (date, title, description, location, billtype, link) VALUES(". $t['date'] .",". $t['title'] .", ". $t['description'] .", ". $t['location'] .", ". $t['billtype'] .", ". $t['link'] .")";
     //     $inres = $mysqli->query($sql);
   //       echo "worked: ".$t['title'];
break;
   }
   ?>

出于某种原因,我无法真正弄清楚,我认为这是因为我不确定我发送给php的对象类型,即使我已经尝试了所有,为什么它不被php看到和' print_r($info)是空的,没有错误?

有什么想法吗?

Thanks in Advance

安德鲁

我认为你的json_encode在javascript中有问题,因为它的结果是一系列[object object]。它出故障了。

通常使用JSON。