Side navigation
#4453 closed bug (worksforme)
Opened March 30, 2009 04:30PM UTC
Closed June 15, 2010 02:54AM UTC
Last modified November 01, 2010 09:28PM UTC
Ajax issues on Safari 3
Reported by: | kwhinnery | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | ajax | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When you use headers to set the "Content-Type" header for a request, this breaks in Safari. jQuery parses the dataType parameter and sets the "Content-Type" header once, which usually is fine, but if I try and manually set "Content-Type" header in the beforeSend method, Safari combines the default with the header I set:
jQuery.ajax({
url: 'foos.json',
data: myJsonString,
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-Type","application/json");
},
success: function(data) {
//do something
}
});
In Safari, because jQuery defaults "Content-Type" to "application/x-www-form-urlencoded", the text of the "Content-Type" header is set to
"Content-Type": "application/x-www-form-urlencoded, application/json"
Which obviously does not work. Really Safari should just overwrite the header's content when it is reset, but it does not. The workaround is of course to just use the contentType parameter to $.ajax, but I should technically be able to set the header and have the same behavior.
Since there is a documented way to set the Content-Type, it seems like a second way is not needed. There is already an enhancement ticket open for more general header handling in #1118 and this might be addressed if that ticket is tackled.