-1
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);

Not getting exact response

getting

Array[0]length: 0__proto__: Array[0]concat: concat()constructor: Array()copyWithin: copyWithin()entries: entries()every: every()fill: fill()filter: filter()find: find()findIndex: findIndex()forEach: forEach()includes: 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(Symbol.iterator): values()Symbol(Symbol.unscopables): Object__proto__: Object

Akki Verma
  • 49
  • 7
  • 1
    [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Jomoos Jul 04 '17 at 14:05
  • Anything you want to do with the ajax response should be done in the .done function, like pushing it to an array (you got that part) and then logging the array (oops). – James Jul 04 '17 at 14:07
  • how to access the response value outside done function – Akki Verma Jul 05 '17 at 04:35

1 Answers1

0

Ajax is asynchronous call , your console.log executed before you push the data , try console.log after you push into array

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);
        }
    });
Srinivas ML
  • 732
  • 3
  • 12