var response = [];
$.ajax({
method: "GET",
url: "{{url('api/xyz')}}",
})
.done(function( res ) {
var rr;
if(res.status == 'success'){
rr = res.data;
response.push(rr);
}
});
console.log(response);
没有得到确切的回复
获得
Array [0] length:0__proto__:Array [0] concat:concat()构造函数:Array()copyWithin:copyWithin()entries:entries()every:every()fill:fill()filter:filter() find:find()findIndex:findIndex()forEach:forEach()包括:includes()indexOf:indexOf()join:join()keys:keys()lastIndexOf:lastIndexOf()length:0map:map()pop:pop ()push:push()reduce:reduce()reduceRight:reduceRight()reverse:reverse()shift:shift()slice:slice()some:some()sort:sort()splice:splice()toLocaleString:toLocaleString ()toString:toString()unshift:unshift()符号(Symbol.iterator):values()符号(Symbol.unscopables):Object__proto__:Object
答案 0 :(得分:0)
Ajax是异步调用,在推送数据之前执行console.log,在推入数组后尝试console.log
var response = [];
$.ajax({
method: "GET",
url: "{{url('api/xyz')}}",
})
.done(function( res ) {
var rr;
if(res.status == 'success'){
rr = res.data;
response.push(rr);
console.log(response);
}
});