我想把键值传递到php页面。
在php页面,我将通过匹配ajaxcallid开始读取值。
但它不起作用。
这与语法/我传入导致错误的方式有关。
parse error
invalid json: ajax call id is missing JavaScript/AJAX:
var person = {
"Address" : "123 Anywhere St.",
"City" : "Springfield",
"PostalCode" : 99999
};
alert(person);
person= JSON.stringify(person);
alert(person);
$.ajax({
url: 'ROOT_URL/admin/ajaxtest.php',
type: "POST",
dataType: 'json',
data: {ajaxcallid: '26', jsarr: person},
timeout: 5000,
success: function(output) {
alert(output.Address);
},
});PHP:
<?php
if (isset($_REQUEST['ajaxcallid']))
{
if($_REQUEST['ajaxcallid']==26)
{
//example, I want to read value of person.Address, person.City,
//person.PostalCode
//what is the easiest way
$phparr= json_decode($_REQUEST['jsarr']);
//do all other operation
$output= json_encode($phparr);
}
}
else
{
$output= "ajax call id is missing";
}
echo $output;
?>发布于 2013-04-25 21:24:36
如果您没有使用dataType:'json',则可能需要使用带斜杠
$.post(window.data.baseUrl, {posts : JSON.stringify(posts)});在php中:
$posts = json_decode(stripslashes($_POST['posts']));发布于 2013-03-13 16:26:15
这对我很有帮助:
data = json_decode($this->request->data['jsarr'], true);在用于访问记录的php代码中
希望它能帮助到一些人!
发布于 2011-02-14 13:57:54
我要猜一猜,你不应该把任何东西串起来。我相信JQuery会为你做到这一点的。即,no person = JSON.stringify(person)。试一试。
https://stackoverflow.com/questions/4989171
复制相似问题