Tutorial :Unable to change session variable through AJAX in IE


I'm getting some weird behavior from IE when trying to change a session variable on the server using AJAX. It works fine in FF, Chrome, Safari, and all the others I've tested but not in IE.

I'm maintaining a list of variables (integers) in a session variable for anonymous users so I can keep their data when/if they register on the site. I'm using jQuery and AJAX to call a Django function that updates the session variable.

The odd behavior in IE is that on refresh (hitting the server again) the session is still not updated. Only when I clear the browser cache or view current cookies does the session update.

Any ideas?


I had the same problem, but with Pylons, what I did was create a middleware that set the following configuration in my response headers.

headers["Cache-Control"] = "no-cache"  headers["Pragma"] = "no-cache"  headers["Expires"] = -  

Here is a description on what this does.


Django already has this built into it's response objects.

response = HttpResponse(data, mimetype='application/javascript')  response['Cache-Control'] = 'no-cache'  response['Pragma'] = 'no-cache'  response["Expires"] = ''  return response  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »