ばかげた質問で申し訳ありません。データを取得するためにphpスクリプトにajax呼び出しを行っています。これが私のコードです
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function loadDoc()
{
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)
{
var finallydata=JSON.parse(xmlhttp.responseText);
document.getElementById("myDiv").innerHTML=typeof finallydata;
}
}
var url='http://localhost/path/to/my/script';
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadDoc()">Change Content</button>
</body>
</html>
そして、ここにYIIの私のphpスクリプトがあります
if($timevalue != 0)
{
$model=new Products;
$receivedata=$model->retrieveresult($timevalue);
foreach($receivedata as $finaldata)
{
header('Content-Type: application/json');
echo json_encode(array('table'=>'products',array('productId'=>$finaldata->productId,'productName'=>$finaldata->productName,'Creation_date'=>$finaldata->Creation_date)));
}
}
データの複数のレコードを送信する必要があるため、1 つずつ foreach ループを使用できます。私は初心者で、うまくいくかどうかわかりません。誰でも助けてもらえますか?