Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Ajax header not sent in all browsers [RSS Feed]

#1 June 9, 2010 11:53:38

David E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Ajax header not sent in all browsers


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-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 9, 2010 20:03:16

R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 12, 2010 07:59:08

David E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Ajax header not sent in all browsers


Ok, that helped narrow things down a little bit. It seems that IE is
receiving the AJAX header after all. For some reason my JavaScript doesn't
always get rendered correctly in IE, but if I clear the browsing history,
cookies, temp files, etc., it works (at least until it starts caching things
again). So I'll have to play some more with that one.

Firefox is still not receiving the AJAX header, however, and I did download
the Tamper data add-on, and when the Tamper Popup window appears, it
indicates that it IS sending an AJAX header:

X-Requested-With: XMLHttpRequest

However, it seems like request.is_ajax() is not picking it up (maybe it's
different than HTTP_X_REQUESTED_WITH?). The code I used for that URL is:

def is_ajax_working(request):
if request.is_ajax():
return HttpResponse("Received AJAX header %s." %
request.META, mimetype="text/plain")
else:
return HttpResponse("Did not receive AJAX header.",
mimetype="text/plain")


Opera also fails every time. Safari and Chrome, however, work like a charm,
so I'm kind of at a loss here. Any other possibilities? Thanks.


On Wed, Jun 9, 2010 at 12:00 PM, Ryan <ryan.nieme...@gmail.com> wrote:

> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

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

Offline

#4 June 14, 2010 00:57:23

David E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Ajax header not sent in all browsers


Ok, so I was able to fix the caching issue with IE by using $.ajax instead
of $.get and setting the cache option to false.

I was reading something about Firefox blocking all AJAX requests when it
thinks that you're going across different domains - it thinks it's XSS -
cross-site scripting. Apparently Opera must work the same way, since it
doesn't respond to my AJAX requests either.

So my question now is: Is there a way to test AJAX calls using the Django
development server in Firefox and Opera?


On Fri, Jun 11, 2010 at 11:58 PM, David Escobar <davidesco...@ieee.org>wrote:

> Ok, that helped narrow things down a little bit. It seems that IE is
> receiving the AJAX header after all. For some reason my JavaScript doesn't
> always get rendered correctly in IE, but if I clear the browsing history,
> cookies, temp files, etc., it works (at least until it starts caching things
> again). So I'll have to play some more with that one.
>
> Firefox is still not receiving the AJAX header, however, and I did download
> the Tamper data add-on, and when the Tamper Popup window appears, it
> indicates that it IS sending an AJAX header:
>
> X-Requested-With: XMLHttpRequest
>
> However, it seems like request.is_ajax() is not picking it up (maybe it's
> different than HTTP_X_REQUESTED_WITH?). The code I used for that URL is:
>
> def is_ajax_working(request):
> if request.is_ajax():
> return HttpResponse("Received AJAX header %s." %
> request.META, mimetype="text/plain")
> else:
> return HttpResponse("Did not receive AJAX header.",
> mimetype="text/plain")
>
>
> Opera also fails every time. Safari and Chrome, however, work like a charm,
> so I'm kind of at a loss here. Any other possibilities? Thanks.
>
>
> On Wed, Jun 9, 2010 at 12:00 PM, Ryan <ryan.nieme...@gmail.com> wrote:
>
>> 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<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-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>>http://groups.google.com/group/django-users?hl=en.
>>
>>
>

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

Offline

  • Root
  • » Django
  • » Ajax header not sent in all browsers [RSS Feed]

Board footer

Moderator control

Enjoy the 15th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support