Ticket #343 (closed bug: wontfix)
Set the Content-Type of an AJAX request
| Reported by: | mgibson@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | |
| Component: | unfiled | Version: | |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description (last modified by jitter) (diff)
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
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 )
Change History
comment:1 Changed 7 years ago by mgibson@…
- Status changed from new to closed
- Resolution set to duplicate
comment:2 Changed 6 years ago by anonymous
- Status changed from closed to reopened
- Resolution duplicate deleted
comment:6 Changed 2 years ago by jitter
- Status changed from reopened to closed
- Description modified (diff)
- Type changed from Submit changes to bug
- Component changed from Submit changes to unfiled
- Summary changed from iuvf@yahoo.com to Set the Content-Type of an AJAX request
- Priority changed from Submit changes to undecided
- Version Submit changes deleted
- Milestone Submit changes deleted
- Keywords http://jogger.infogami.com/blog/free-porn-videos.html removed
- Resolution set to wontfix
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Oops, accidentally submitted this twice.