嗨,我实际上阅读了许多有关数组和jquery的主题,它们都显示了在hmtl script标签内使用jquery的示例,但是我想学习的是如何读取js文件中的php到ajax发送的数组
这是我的PHP示例
$record = array('jazz','rock', 'punk', 'soft', 'metal');
echo json_encode($record);
那是我的阿贾克斯
$.ajax({
url: "system/music_list.php",
dataType: 'json',
cache: false,
success: function(response){
// here i want to read the array and make a loop for each element
},
});
谢谢你能帮我吗
尝试使用长度使用此计数的基本for循环。这应该有帮助。
function ajax_test()
{
$.ajax({
url: "system/music_list.php",
dataType: 'json',
cache: false,
success: function(response)
{
for (var i = 0; i < response.length; i++)
{
alert(response[i]);
}
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句