代码:
$(function(){
var Name = [];
for($i=1; $i<16; $i++) {
var id = $i;
$.post("./index.php", {
record : id
}, function(data){
Name.push(data);
});
}
alert(Name);
});
数据返回结果为<a href="#"><img src="./name.jpg"></a>
请告诉我为什么数据没有添加到数组中?
最佳答案
post 请求
是一个异步方法。
甚至在点击成功功能之前,您就会点击警报。
Asynchronous means that the script will send a request to the
server, and continue its execution without waiting for the reply.
关于javascript - 为什么不在数组中添加元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14579794/