Skip to main content

Bug Tracker

Side navigation

#343 closed bug (wontfix)

Opened November 02, 2006 09:40AM UTC

Closed November 26, 2010 11:13AM UTC

Set the Content-Type of an AJAX request

Reported by: mgibson@designlinks. Owned by:
Priority: undecided Milestone:
Component: unfiled Version:
Keywords: 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 (0)
Change History (3)

Changed November 02, 2006 09:47AM UTC by mgibson@desi comment:1

resolution: → duplicate
status: newclosed

Oops, accidentally submitted this twice.

Changed January 27, 2007 03:01PM UTC by anonymous comment:2

resolution: duplicate
status: closedreopened

Changed November 26, 2010 11:13AM UTC by jitter comment:3

component: Submit changesunfiled
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 )\ \ \ 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 ) \ \ \
keywords: http://jogger.infogami.com/blog/free-porn-videos.html
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