#342 closed enhancement (invalid)
spam
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | major | Milestone: | |
Component: | ajax | Version: | |
Keywords: | Content-Type | Cc: | |
Blocked by: | Blocking: |
Description
I'd like to suggest an additional option for $.ajax() to allow an alternative Content-Type, eg: application/json
I'd like to send raw JSON data to a PHP script, but PHP requires that a Content-Type other than the usual 'application/x-www-form-urlencoded' is set before it allows you to access the raw request data (via $HTTP_RAW_POST_DATA).
This will also allow the correct submission of XML, and other formats.
I've attached a patch against ajax.js
Cheers
- Mark Gibson
Index: ajax.js =================================================================== --- ajax.js (revision 512) +++ ajax.js (working copy) @@ -686,6 +686,7 @@
var success = type.success; var error = type.error; var dataType = type.dataType;
"application/x-www-form-urlencoded"; |
var global = typeof type.global == "boolean" ? type.global : true; var timeout = typeof type.timeout == "number" ? type.timeout : jQuery.timeout;
ifModified = type.ifModified false;
@@ -708,7 +709,7 @@
Set the correct header, if data is being sent if ( data )
- xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xml.setRequestHeader("Content-Type", contentType);
Set the If-Modified-Since header, if ifModified mode. if ( ifModified )
Attachments (2)
Change History (12)
comment:1 Changed 16 years ago by
comment:2 Changed 16 years ago by
Cc: | Adrianna added |
---|---|
Component: | ajax → 1 |
Keywords: | Adrianna added; Content-Type removed |
Milestone: | → 1 |
Priority: | minor → 1 |
Summary: | Set the Content-Type of an AJAX request → Adrianna |
Type: | enhancement → 1 |
Version: | → 1 |
comment:3 Changed 16 years ago by
Cc: | Adrianna removed |
---|---|
Component: | → ajax |
Keywords: | Content-Type added; Adrianna removed |
Priority: | → major |
Summary: | Adrianna → Set the Content-Type of an AJAX request |
Type: | → enhancement |
Restored, after spam.
comment:4 Changed 16 years ago by
New patch against rev 540:
Index: ajax.js =================================================================== --- ajax.js (revision 541) +++ ajax.js (working copy) @@ -701,6 +701,7 @@ success: fvoid, error: fvoid, dataType: null, + contentType: "application/x-www-form-urlencoded", data: null, url: null }, s); @@ -736,7 +737,7 @@ // Set the correct header, if data is being sent if ( s.data ) - xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xml.setRequestHeader("Content-Type", contentType); // Set the If-Modified-Since header, if ifModified mode. if ( s.ifModified )
(Add attachment didn't seem to work!)
comment:5 Changed 16 years ago by
Sorry, slight typo in above patch, replace with this line:
xml.setRequestHeader("Content-Type", s.contentType);
I blame the spamming gits! They've really pissed me off!
comment:6 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:7 Changed 16 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:8 Changed 16 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Summary: | Set the Content-Type of an AJAX request → spam |
comment:9 Changed 16 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
comment:10 Changed 16 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Sorry, wiki screwed up the patch, here it is again: