【发布时间】:2013-06-06 15:45:22
【问题描述】:
我发送这个:
switch=rssAdd&data=[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象] ],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[object 对象],[object 对象],[object 对象],[object 对象]
这是由此创建的:
$(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) 为空,没有错误?
有什么想法吗?
提前致谢
安德鲁
【问题讨论】:
-
您是否尝试过不先进行 json_encoding 发送?如果是这样,会发生什么?
-
json_encode应该是JSON.stringify -
嗨,凯尔,我已经尝试过了,没有发送任何东西,假设它是一个 json,因为我以为我就是这样创建它的。
-
嗨丸。做到了。谢谢你:)