I’m using jQuery to send an ajax request for Django. To select the response template I’m checking the request like this:
def about(request) :
context = {'content' : 'about.html',
'section_nav' : 'about_nav.html'}
if request.is_ajax() :
context['ajax'] = True
return render_to_response('main.html', context)
In main.html I check either if is ajax or not and extend a different template.
And the jQuery is simple as:
$.get('/about/', function(data) {
$('.article').html(data);
});
In Chrome and Firefox it works just fine… but IE9 returns False in request.is_ajax() and loads the page with the wrong context.
How can I overcome this problem, and make an ajax request from IE (with jQuery) and recognize it with django?
Try using
$.ajaxinstead of$.get. I’ve read that using$.ajaxworks with all browsers but$.getwon’t send the ajax header with IE.Also set the cache option to false.