我想通過ajax請求並將每個結果(從for循環)的一些值從JavaScript傳遞到一個PHP文件,以使用PHP數組。PHP的循環和存儲在陣列
queryData={"data":{"data_string":{"data":"medicine","default_field":"Content"}}}
testArgument=0;
$.ajax({
url:"test/queryManipulate.php",
type: 'POST',
datatype: 'json',
data: {field : queryData, start : testArgument},
success:function(jsonQuery)
{
alert(jsonQuery);
}
});
<?php
$i=0;
for ($from = 0; $from <= 50; $from+=10)
{
$object=json_decode($_POST["field"]);
$object->from=$from;
$object=json_encode($object);
$ch = curl_init("http://localhost:9200/algotree//_search");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $object);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$test= curl_exec($ch);
curl_close ($ch);
$newArray[$i]= $test;
$i++;
echo $newArray[2];
}
?>
MY for循環不起作用。我是否正確使用它,以及如何將每個結果存儲到php中的數組?
你爲什麼不嘗試使用json_decode?這將把你的JSON自動轉換成一個數組...我在你的例子中看到的是你沒有在請求上傳遞'start'的值,所以也許這就是你的問題 – pollirrata 2012-07-17 02:30:48
Im在數據字段的請求處傳遞起始值..我安娜存儲結果在separatearray .. – user1371896 2012-07-17 02:33:01
什麼是相當於javascript for循環在php?像arrayname [i] = result .. i ++; – user1371896 2012-07-17 02:41:53