Problem with AJAX request return

Asked

Viewed 269 times

1

I am making a request in ajax but the result 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 make the request manually by the browser (right in the address bar) it updates, but using the JS function the value is always the same.

Can anyone tell me what it might be?

  • And when you call the function 'Actualiztotalitensnote'?

  • would be after deleting an item from the note, is inside another ajax request:

  • what comes in result? Success: Function (result) { ///put a console.log(result) here and show, please. $("#totalitens"). text(result) }

  • Then, comes the total value of note items, however I delete the item and if I make the request manually from the browser bar the item is updated normally. I have already made an Alert test, it enters the function, however the value that returns in the result is always the last of the request I made directly through the browser bar.

  • Post the entire code snippet, it’s easier to help like this...

2 answers

2


What happens is actually cache, what you can do is send a random parameter in your request, or disable the cache in the request. To disable the cache 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 the cache: false, in the request

  • Thank you very much, resolvel =D

0

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

http://api.jquery.com/jquery.ajax/

Adding cache:false should solve the problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.