Problem with return of AJAX request

1

I am making a request in ajax but the result of it does not update, it is as if it were in some kind of cookie.

function AtualizaTotalItensNota(idFornec) {
   
   
   $.ajax({
	    type: "GET",
	    dataType: "text",
	    url: "/sistema/compras/entrada/getitens/" + idFornec,
	    success: function (result) {
		  $("#totalitens").text(result)
	    }
	});
   
}

If I do the request manually by the browser (direct in the address bar) it updates, but using the JS function the value will always remain the same.

Can anyone tell me what it can be?

    
asked by anonymous 17.01.2017 / 12:39

2 answers

2

What happens is actually caching, what you can do is to send a random parameter to your request, or disable the cache in the request. To disable caching, just do it this way:

function AtualizaTotalItensNota(idFornec) {


   $.ajax({
        cache: false,
        type: "GET",            
        dataType: "text",
        url: "/sistema/compras/entrada/getitens/" + idFornec,
        success: function (result) {
          $("#totalitens").text(result)
        }
    });

}

You can check that I added cache: false, to the request

    
17.01.2017 / 12:49
0

In the jquery documentation it is described that request caching is enabled by default EXCEPT for the 'script' and 'jsonp' types

link

Adding the cache option: false should solve the problem

    
17.01.2017 / 12:48