I'm developing a Firefox extension that uses an ajax-request to retrieve information. This is the code:
$.ajax({
url: "http://127.0.0.1/foo/bar/Service?wsdl" + new Date().getTime(),
beforeSend: function(request) { request.setRequestHeader("SOAPAction", "Group"); },
async: false,
cache: false,
type: "POST",
dataType: "xml",
data: req,
contentType: "text/xml; charset=\"utf-8\"",
success: function (data, textStatus, xmlHttpRequest) {
out = $(xmlHttpRequest.responseXML);
}
});
I still get the same result, when the data that is sent to the server is changed. I tried to avoid that by adding "new Date().getTime()" to the URL and "cache: false". This doesn't seem to work. After restarting the browser, I get the correct results.
Does anyone have an idea what the problem is? Is there some kind of session-handling, so the server still gives back the old response?
Edit: I did a lot of testing and debugging and I think I found the problem: there is a cookie saved with every ajax-request that contains a session-id, so every time I do the request again, the server sends data of the session with the session-id in the cookie. Really bad behavior, I didn't know that cookies could be created through an ajax-request. So everything I have to do to fix the problem is a function that deletes this cookie every time my parameters are changed. Thanks for your help again.
Although we can use a standard caching solution provided by HTTP (yes, Ajax is cached by HTTP), there is a catch: It works for GET requests only (not POST).
Fact #1 : Ajax Caching Is The Same As HTTP Caching At this level, the browser doesn't know or care about Ajax requests. It simply obeys the normal HTTP caching rules based on the response headers returned from the server. If you know about HTTP caching already, you can apply that knowledge to Ajax caching.
The jqXHR Object. The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method.
Can you try this
$(document).ready(function() {
$.ajaxSetup({ cache: false });
});
try toger with Math.random() to be on safer side
Date().getTime() together with Math.random()
http://127.0.0.1/foo/bar/Service?wsdl" + new Date().getTime() + Math.random()
Try an ampersand before the timestamp:
http://127.0.0.1/foo/bar/Service?wsdl&" + new Date().getTime()
I guess the wsdl-parameter makes sense there inside the url, without the ampersand you destroy the parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With