简体   繁体   中英

getJSON callback issues

I am trying to implement the following code to read json data from a url which is in the form of

[{"name": "Adam", "country":"US","Age":"21"},{"name":"...."}]

I'm able to see the first log console.log(here) but it is not entering the second log console.log(jsonhere) , any thoughts on where I have made a mistake?

CODE:

$(document).ready(function () {
    console.log("here");
    var url = "url";

    $.getJSON(url + "?callback=?", null, function (data) {
        console.log("jsonhere");
        $.each(data, function (idx, obj) {
            $.each(obj, function (key, value) {
                $('#tw2').append(key);
                console.log(key + ": " + value);
            });
        });
    });
});

The known issue for $.getJSON() is that it caches the response after the first request. If the same request is made (same URL and parameters), it will never hit the server. Instead, it picks the response from cache.

To force clear the cache for every request use: ajaxSetup({cache: false}) or

use $.ajax() with dataType:'json' and cache:false .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM