views:

63

answers:

3

I Using this code

<script type="text/javascript">
$(function() {
    $('#DoTask').click(function(event) {
        event.preventDefault(); // added this
        $.getJSON('/TareasBackGround/DoTaskInteractivo', null,
                function(response) {
                    $('#ResultadoEjecutarTarea').html("<br />Resutado:" + response.result);
                    $('#ResultadoEjecutarTarea').css("style", "");


                });
    });
});

After the first call I get always the same result. I add the time stamp to the result to check this.

Any ideas?

+1  A: 

You're probably caching the result the first time, so when you request it the second time you get the same (cached) timestamp.

Tomas Lycken
+1  A: 

The response is probably cached. You can set the Ajax option cache to false or add a timestamp at the request:

currentTime= (new Date()).getTime();    
url = '/TareasBackGround/DoTaskInteractivo?_=' + currentTime;
kgiannakakis
How do I turn off the cache?
Jedi Master Spooky
I try the '/TareasBackGround/DoTaskInteractivo?_=[current time in millis here]' like this '/TareasBackGround/DoTaskInteractivo?_=<%= DateTime.Now.Millisecond %>' Get the same behavior.
Jedi Master Spooky
You need to re-calculate the current time at the client, not just once at the server.
kgiannakakis
+1  A: 

Add this:

$.ajaxSetup ({cache: false});

right above your click event. This should prevent the ajax request from caching.

Jon