Side navigation
#5123 closed bug (fixed)
Opened August 25, 2009 03:31PM UTC
Closed June 15, 2010 03:09AM UTC
Last modified March 10, 2012 06:59AM UTC
Chrome $.ajax doesn't work without data option
Reported by: | coxmatthew | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.4.3 |
Component: | ajax | Version: | 1.4.2 |
Keywords: | ajax chrome | Cc: | |
Blocked by: | Blocking: |
Description
Found that my ajax processing wasn't working in chrome. Although the same request using $.post() worked fine.
Workaround:
adding an empty data attribute (data: "") seems to work around this issue.
Details:
----------------------------
Succeeds
----------------------------
$.post("test.php",
function(data){
alert("Test results: " + data);
},
"text");
--------------------------------
Throws error in chrome (ver 2.0.172.39)
----------------------------------
jQuery.ajax({
type: "POST",
url: "test.php",
success: function(data){
alert("Test results: " + data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error with ajax Function: "+ textStatus+" "+errorThrown);
},
dataType: "text"
});
----------------------------
Succeeds
//----------------------------
jQuery.ajax({
type: "POST",
url: "test.php",
data: "",
success: function(data){
alert("Test results: " + data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error with ajax Function: "+ textStatus+" "+errorThrown);
},
dataType: "text"
});
Attachments (1)
Change History (5)
Changed February 11, 2010 11:40PM UTC by comment:1
Changed February 15, 2010 09:56PM UTC by comment:2
The real problem is that the XMLHttpRequest.send function on Chrome passes 'undefined' over the wire when given an undefined value instead of an empty string like Firefox/Safari/etc. There is an open ticket on the chromium project that describes this behavior: Issue 33062: XMLHttpRequest.send sends 'undefined' string when passed undefined value
In jQuery, the
jQuery.ajaxfunction passes in
jQuery.ajaxSettings.dataeven when it's undefined. The final call to xhr.send is on ajax.js line 482.
I can bypass this problem by setting
jQuery.ajaxOptions.data = nullon page load.
But the problem is subtle: rails param parsing just blows up without explanation. I suspect the best fix will be simply setting
jQuery.ajaxSettings.datato
nullinstead of leaving it undefined as on line 173 of ajax.js.
Changed March 30, 2010 09:51PM UTC by comment:3
This bug bit us today. Patch with test attached.
Changed June 15, 2010 03:09AM UTC by comment:4
milestone: | 1.3.2 → 1.4.2 |
---|---|
resolution: | → fixed |
status: | new → closed |
version: | 1.3.2 → 1.4.2 |
Changed June 15, 2010 03:09AM UTC by comment:5
milestone: | 1.4.2 → 1.4.3 |
---|
Seeing the same issue in Chrome 4.0.249.78 (36714). It handling without a data option present seems to make the calls fail. The browser error is really pretty random :
I did a trace on the browsers differences in posts :
Firefox 3.5.7
Chrome 4.0.249.7
Seems Chrome is getting the ''Content-Type'' set as application/xml. I'm not sure if this is a jquery issue or chrome. Looking at the actual xml is the word 'undefined', not valid XML-which is probably causing the server to fail and send back the failed response-or at least this was the situation in my case.
We just used GETs in our situation as a POST wasn't needed.