Side navigation
#342 closed enhancement (invalid)
Opened November 02, 2006 09:40AM UTC
Closed December 19, 2006 06:59PM UTC
Last modified June 19, 2007 07:59AM UTC
spam
Reported by: | mgibson@designlinks. | 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;
+ var contentType = type.contentType || "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 (10)
Changed November 02, 2006 09:55AM UTC by comment:1
Changed November 05, 2006 03:51PM UTC by comment:2
cc: | → Adrianna |
---|---|
component: | ajax → 1 |
keywords: | Content-Type → Adrianna |
milestone: | → 1 |
priority: | minor → 1 |
summary: | Set the Content-Type of an AJAX request → Adrianna |
type: | enhancement → 1 |
version: | → 1 |
Changed November 07, 2006 05:03PM UTC by comment:3
cc: | Adrianna |
---|---|
component: | → ajax |
keywords: | Adrianna → Content-Type |
priority: | → major |
summary: | Adrianna → Set the Content-Type of an AJAX request |
type: | → enhancement |
Restored, after spam.
Changed November 07, 2006 05:09PM UTC by comment:4
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!)
Changed November 07, 2006 05:16PM UTC by comment:5
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!
Changed November 07, 2006 07:33PM UTC by comment:6
resolution: | → fixed |
---|---|
status: | new → closed |
Changed December 18, 2006 11:01AM UTC by comment:7
resolution: | fixed |
---|---|
status: | closed → reopened |
Changed December 18, 2006 10:16PM UTC by comment:8
resolution: | → invalid |
---|---|
status: | reopened → closed |
summary: | Set the Content-Type of an AJAX request → spam |
Changed December 19, 2006 12:45PM UTC by comment:9
resolution: | invalid |
---|---|
status: | closed → reopened |
Changed December 19, 2006 06:59PM UTC by comment:10
resolution: | → invalid |
---|---|
status: | reopened → closed |
Sorry, wiki screwed up the patch, here it is again: