【发布时间】:2012-08-28 06:42:14
【问题描述】:
我在尝试将 JSON 从 javascript 发送到 PHP 脚本时遇到了很长时间:发送很好(我可以在提琴手中看到 JSON)但我在 @ 中什么也没收到987654325@:
javascript:
var person = {
name: 'yoel',
age: 28
};
xmlhttp.open("POST","http://localhost:8888/statisticsdb.php",true);
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send(JSON.stringify(person));
php:
echo 'trying to print ' . var_dump($_POST["name"]);
我显然希望看到一些东西,但 var_dump 什么也没返回。非常感谢您的帮助!
【问题讨论】:
-
你可以使用 jQuery,它有一个非常简单的 $.post() 方法,你可以简单地将 JSON 对象作为参数传递: $.post('URL',person,success:function() )
标签: php javascript json post