How to work with Ajax with JQuery?

Posted on

Question :

I have the following function:

function getJson() {

            async : false

        $.getJSON(baseURL + "/ObterCursos",
                function(data) {
                        $.each(data, function(key, val) {
                                "Codigo" : val.Codigo,
                                "Nome" : val.Nome

The first time it’s called, it takes a while to get the results, but the next few times it works quickly. But I discovered that if I compile this code in a Cordova project, even though it is called again and there are different values being returned from the request, this method does not update the results. What can I do to resolve this?


Answer :

This can be a cache-related problem. To test / solve you can do 2 things:

1- Turn off the Jquery cache. Set cache: false, in ajax setup.

    async : false,
    cache: false

2 – Put a timestamp in the url for the url to be always different and force the browser to make the request without cache. For example:

var timestamp = new Date().getTime();
$.getJSON(baseURL + "/ObterCursos?ts=" + timestamp, function(data) {


Leave a Reply

Your email address will not be published. Required fields are marked *