Bug Tracker

Opened 16 years ago

Closed 15 years ago

#1623 closed bug (worksforme)

$.ajax not sending X-Requested-With with dataType script

Reported by: jeremydurham Owned by:
Priority: minor Milestone: 1.2.2
Component: core Version: 1.2
Keywords: xhr x-requested-with ajax Cc:
Blocked by: Blocking:

Description

I'm attempting to call the following code with jQuery 1.2:

$.ajax({async:true, dataType:'script', type:'POST', url:'/foo/bar'}); return false;

With jQuery 1.1.x, I was getting back an X-Requested-With of XMLHttpRequest; with jQuery 1.2 I do not get the X-Requested-With back. It seems to be because jQuery 1.2 injects a script tag into the header of the page, whereas jQuery 1.1.4 does not.

Ruby on Rails checks that the X-Requested-With header is set to determine if this is an XML Http request.

Attachments (2)

jquery_test.html (864 bytes) - added by davidserduke 15 years ago.
test case (built based on description)
load.js (28 bytes) - added by davidserduke 15 years ago.
test case data

Download all attachments as: .zip

Change History (3)

Changed 15 years ago by davidserduke

Attachment: jquery_test.html added

test case (built based on description)

Changed 15 years ago by davidserduke

Attachment: load.js added

test case data

comment:1 Changed 15 years ago by davidserduke

Milestone: 1.2.11.2.2
Resolution: worksforme
Status: newclosed

This may or may not have been a problem in 1.2, but when tested in 1.2.1 it works as expected. Using the above test case with FireBug, I found the X-Requested-With was set

Request Headers
Host localhost
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://localhost/jquery/test/1623/jquery_test.html
Pragma no-cache
Cache-Control no-cache

If it is a cross domain script load (i.e. the url starts with "http") then yes, that will not be set since XMLHttpRequest won't be used but rather the script is inserted in the head element.

Note: See TracTickets for help on using tickets.