0
我有JavaScript代碼將數據發送到PHP。AJAX數據未到PHP
爲什麼我無法獲取JSON數據?
xhr = new XMLHttpRequest();
var url = "http://192.168.1.4/temp.php";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var json = JSON.parse(xhr.responseText);
}
}
var aa = [{
"email": "[email protected]",
"password": "101010"
}, {
email: '[email protected]',
"passqword": "112"
}];
xhr.send(aa);
我創造這樣的PHP代碼來獲取數據:
<?php
header('Access-Control-Allow-Origin: *');
header("Content-Type: application/json");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
$v = json_decode(stripslashes(file_get_contents("php://input")));
echo $v;
?>
閱讀['__POST'](http://php.net/manual/en/reserved.variables.post.php) –
沒有關於json數據 – kohli
什麼顯示在控制檯中? – Jaber