作者:霸气的艳子_612 | 来源:互联网 | 2023-05-24 23:33
1> jeroen..:
您误解了Javascript和php的关系;该php仅在页面加载时呈现一次,因此您无法echo
在Javascript success
处理程序中返回php数据。
相反,您的php脚本输出的所有内容都将在Javascript变量中可用:
success: function(vnvlist) {
// ^^^^^^^ this is what has been outputted by php, the
// json already parsed
// your data is available in `vnvlist`
// var prevnvlist = '';
// with dataType='json' you don't need to parse anything
// as jQuery will parse it for you
// var vnvlist = JSON.parse(prevnvlist);
// so all you need is this...
alert('success');
for (var x = 1; x <= vnvlist.length; x++) {
var vnv = vnvlist[x]['VnVMethod'];
vnvSel.options[vnvSel.options.length] = new Option(vnv, vnv);
}
},
并且您需要确保php仅输出您的json字符串:
...
// The following line when read in the log file shows a valid JSON array
$log->lwrite('array '.json_encode($dataVnvMethods));
// output your data so that it is available on the client-side
echo json_encode($dataVnvMethods);
$log->lwrite('Ending debug');
...