如何将.getjson转换为.ajax

How to convert .getJSON to .ajax

本文关键字:ajax 转换 getjson      更新时间:2023-09-26

如何转换:

    var dataURL = 'http://example.com/data.json';
    var queryOptions = {
        start: Date.parse('today - 15 years').getTime()/1000,
        end: Date.parse('today').getTime()/1000
    }
    $.getJSON(dataURL, queryOptions, function(jsonresult) {

…jQuery .ajax调用?

$.ajax({
    url: dataURL
    data: queryOptions,
    dataType: 'json',
    success:function(jsonresult){
        //json here
    }
});

虽然,$.getJSON()只是$.ajax()方法的一个简短的JSON准备包装器。

$.ajax({
    type: "GET",
    url: dataURL,
    dataType: "json",
    data: queryOptions,
    success: function(result) {
        //
    },
    error: function(xhr, status, error) {
        //
    }
});