Wednesday, June 9, 2010

Re: Ajax header not sent in all browsers

If you simplify things down to something like the snippets below, does
the alert display 'Said it was NOT ajax' for you? It shouldn't (and
doesn't for me).

Also, do you have the Tamper Data Firefox add-on installed to validate
the headers being sent in? That could help narrow things down.

urls.py:

(r'^isajax/?$', 'some_site.views.is_ajax_worky'),

views.py:

def is_ajax_worky(request):
ajax_header = request.META.get('HTTP_X_REQUESTED_WITH', 'None')
if request.is_ajax():
return HttpResponse('Said it WAS ajax. header=' + ajax_header)
return HttpResponse('Said it was NOT ajax. header=' + ajax_header)

test.html:

<noscript>This test requires javascript!</noscript>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/
libs/jquery/1.4.2/jquery.min.js
"></script>
<script type="text/javascript">
$(document).ready(function() {
$.get('/isajax', function(data) {
alert(data);
});
});
</script>

On Jun 9, 2:14 am, David Escobar <davidescobar1...@gmail.com> wrote:
> Hi everyone,
> I'm using Django 1.1 with jQuery 1.4.2 and currently testing with the
> Django development server. Whenever I send an AJAX request with
> $.get(), the HTTP_X_REQUESTED_WITH header only gets sent with Chrome
> and Safari. It does not get sent with IE or Firefox. I've verified
> this by outputting the request.META keys to a text file for each one.
> Needless to say, my AJAX only works correctly with Chrome and Safari.
> Also, I'm using request.is_ajax() on the Django side.
>
> Does anyone know why this might be occurring? Could it be because I'm
> testing using the Django development server? It seems to me like this
> might be a jQuery issue, but after doing many online searches, I
> haven't seen anyone else run into this problem. Every documentation
> says that jQuery sends HTTP_X_REQUESTED WITH.
>
> Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate