javascriptjqueryjsonajax

Getting entire JSON data from API with AJAX


With my AJAX call, I want to get the JSON data entirely.

For example www.abc.com/api/3 gives {"information":.... json data with many levels...}}

I want to store this data in a variable. So I trid this:

$.ajax({
            async: false,
            type: 'GET',
            dataType: 'json',
            url: url,
            data: data,
            success: function(data) {
                              
                               x=data;// It's wrong, but I don't know how to put whole json into x
        
            }
        })

Solution

  • You can use $.ajax() as a Promise:

    $.ajax({
        type: 'GET',
        url: url,
    }).then((data) => {
      console.log(data);
    });