使用AJAX从API获取整个json数据

问题描述 投票:0回答:1

通过我的AJAX调用,我想完全获取json数据。

例如,www.abc.com / api / 3提供了{“ information”:....具有多个级别的json数据...}}

我想将此数据存储在变量中。因此,我尝试这样做:

$.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

            }
        })
javascript jquery json ajax web
1个回答
0
投票

您可以将$.ajax()用作Promise

$.ajax({
    type: 'GET',
    url: url,
}).then((data) => {
  console.log(data);
});
© www.soinside.com 2019 - 2024. All rights reserved.