我发送这个:
switch=rssAdd&data=[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象]
这是由此创建的:
$(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) 是空的,没有错误?
有任何想法吗 ?
提前致谢
安德鲁