1

With jQuery ajax method I have a request on some file, which returns data in json format. That request is triggered by clicking on some button. Then I display that data as I need. Everything works fine on localhost, but when I moved my project to the server, there was a little problem. The data, which was updated in database and should be shown in that file (formatted in json), does not update, until I refresh the page.

Here is the code:

function myAjaxFunction() {

$.ajax({
    'url' : 'MY_URL',
    'type' : 'POST',
    'cache' : false,
    'data' : 'MY_DATA'
    'dataType' : 'json',
    'success' : function(result) {
     // my code here
    }

});

}


var body  = $("body");
body.on('click', '.some_button', function(e) {
    myAjaxFunction();
    e.preventDefault();
});

And I wonder, is that because, I cache body tag?

4

1 に答える 1

1

add to end of your 'MY_URL' some parameter with random number

'url' : 'MY_URL&'+Math.floor((Math.random()*100)+1),
于 2012-06-13T13:16:24.933 に答える