我正在使用 jQuery、AJAX 和 PHP 更新事件下拉框的内容。我的代码当前触发该事件并使用 AJAX 调用一个 PHP 函数,该函数进入数据库并获取与下拉列表的每个成员关联的记录。
我目前可以将这个二维数组(一个记录数组,每个记录数组中包含一个列数组)返回到我的 jQuery 函数,但我不知道如何将数组转换成我可以使用的东西.
调用 AJAX 的 jQuery 代码:
var element= $('select[name=elementName]');
var data = 'inData=' + element.val();
// Call AJAX to get the info we need to fill the drop downs by passing in the new ID
$.ajax(
{
type: "POST",
url: "ops.php",
data: "op=getInfo&" + data,
success:
function(outData)
{
// WHAT DO I DO HERE TO CONVERT 'outData' INTO A 2-DIMENSIONAL jQUERY ARRAY??
},
error:
function()
{
}
});
PHP代码:
$sqlResults= mysql_query("SELECT data FROM table WHERE id='".$_POST['inData']."'");
$outData = array();
// Fill the data array with the results
while ($outData[]= mysql_fetch_array($sqlResults));
// echo the data to return it for use in the jQuery file
echo $outData;
发布的代码工作正常 - 我只是不知道如何在 jQuery 中读取“outData”。
在此先感谢您的帮助!
最佳答案
关于php - 使用 AJAX 从二维 PHP 数组创建二维 jQuery 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6602103/