PHP
$table = mysql_real_escape_string($_REQUEST['table']);
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = '$table'";
$result = mysql_query($query);
$arr1 = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$arr1[] = $row['COLUMN_NAME'];
}
echo json_encode($arr1);
}
Javascript/Jquery
$("#verticalSelect").change(function() {
var table = $("#verticalSelect option:selected").attr('value');
$.post(PROCESSORFILE, {"task": "getTableDupeFields", "table": table}, function(data) {
$.each(data, function(key, value){
$("#test-area").append(key+' is: '+value+'<br/>');
});
alert(data);
});
});
现在有了返回的 JSON 变量的警报,我得到了我期望的结果。
["lead_id", "callcenter", "monkey" ...]
但是有了这个Jquery.each()
功能,我得到了这个:
0:is: [
1:is: "
2:is: l
3:is: e
4:is: a
5:is: d
6:is: _
7:is: i
8:is: d
9:is: "
10:is: ,
11:is: "
12:is: c
13:is: a
14:is: l
15:is: l
16:is: c
17:is: e
18:is: n
19:is: t
20:是:e
21:是:r
返回数组的每个字符都是循环的,而不是每个离散值。处理 JSON 返回数组的正确方法是什么?