Magento 2 Rest Ajax call appends weird number as parameter
-
15-04-2021 - |
Pergunta
I implemented a custom Rest Api in my module. Until now everythhing works fine. Jquery Ajax is used to call the api. The JS Code is below:
$("#p").click(function(){
$.ajax({
url: "http://127.0.0.1/rest/V1/ajax/l/-100/b/0-300/fo/a/fa/a/p/100-/cat/a",
type: "GET",
beforeSend: function(xhr){
xhr.setRequestHeader('content-type', 'application/json');
xhr.setRequestHeader('cache-control', 'no-cache');
},
success: function(response) { $('#b').html(response);}
});
}); //close onclick
When inspecting the Ajax call in Browser, the following is shown:
Everything works fine and I receive the correct response. But I am asking myself why this number (see red arrow) is automatically appended in the request?
How can I prevent that behavior ?
Solução
This parameter is added by jQuery to circumvent an Internet Explorer behavior. It is only applied to GET
requests and only if cache
is false.
Specify cache: true
in your ajax request to get rid of it.
See jQuery Docs
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange