Hi,
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 )
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to