我正在将 JavaScript 对象发布到 PHP 后端,但无法检索数据。
我发布了这个java脚本对象:
{"name":"Mastermold"}
我正在尝试访问这样的名称:
$name= $_POST["name"];
错误是:
<小时/>{"error":{"type":"ErrorException","message":"Undefined index: name","file":"C:\Program Files (x86)\Ampps\www\app\controllers\JournalsController.php","line":34}}
saveMongoJournal=function(theJournal,doThis) {
journalRoute="http://localhost/public/journals"
$http.post(journalRoute,theJournal).success(doThis);
};
$scope.clicky= function(){
saveMongoJournal( {name: "mastermold"},alertReply);
};
$_POST['name'];
最佳答案
您可以尝试这个(检查this answer)
$data = json_decode(file_get_contents("php://input"));
echo $data->name;
关于Javascript 对象到 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22290326/