Bug Tracker

Opened 13 years ago

Closed 9 years ago

#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:
Blocked by: Blocking:

Description (last modified by jitter)

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 )

Change History (3)

comment:1 Changed 13 years ago by mgibson@…

Resolution: duplicate
Status: newclosed

Oops, accidentally submitted this twice.

comment:2 Changed 13 years ago by anonymous

Resolution: duplicate
Status: closedreopened

comment:6 Changed 9 years ago by jitter

Component: Submit changesunfiled
Description: modified (diff)
Keywords: http://jogger.infogami.com/blog/free-porn-videos.html removed
Milestone: Submit changes
Priority: Submit changesundecided
Resolution: wontfix
Status: reopenedclosed
Summary: iuvf@yahoo.comSet the Content-Type of an AJAX request
Type: Submit changesbug
Version: Submit changes
Note: See TracTickets for help on using tickets.