こんにちは私はJavascriptを使用してAjax経由でPHPにJsonを送信しようとしています。Firebugでデータを表示すると、index.htmlによってデータが正しく送信されます。正しいデータでJsonタイプを示しています。しかし、phpでJSONを読み取ることができないようです。$_POSTを使用してアクセスできません。$ _POST ['name']を使用してみましたが、応答がありません。$ _POSTを使用しようとすると、応答は配列になります。手伝ってくれませんか?
これが私のjavascriptコードです。
<html>
<head>
<script type="text/javascript">
//Create Http request depending on browser
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;}
}
// Function to create
var url = "control.php";
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
var data=JSON.stringify({"name":"John", "time":"2pm"});
xmlhttp.send(data);
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
</body>
</html>
これは私のphpコードです
<?php
include_once('JSON.php');
$json = new Services_JSON();
$value = $json->decode($_POST['name']);
echo $value;
?>
何日もこれに取り組んできました、そして私はあなたが提供できるどんな助けにも本当に感謝します。ありがとうございました!