Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10534 closed bug (invalid)

POST Ajax and contentType sends no data.

Reported by: wildpeaks Owned by:
Priority: low Milestone: None
Component: ajax Version: 1.7b2
Keywords: Cc:
Blocked by: Blocking:


It seems that data is not sent if type POST is used and contentType is specified, however it works with GET.

Both 1.6.4 and 1.7 beta 2 behave the same way, so I'm not sure if this is by design.


Files used in the examples:

  • "index.html" is the page that uses jQuery.
  • "echo.php" prints as JSON the method and data it receives.


Source of echo.php:


print json_encode(
		'method' => $_SERVER['REQUEST_METHOD'],
		'request' => $_REQUEST



Source of index.html:


	<input id="get-without" type="button" value="GET: WITHOUT contentType" />
	<input id="get-with" type="button" value="GET: WITH contentType" />

	<input id="post-without" type="button" value="POST: WITHOUT contentType" />
	<input id="post-with" type="button" value="POST: WITH contentType" style="color: red" />

	<script src="http://code.jquery.com/jquery-1.7b2.js"></script>
	<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>-->

		function send(type, contentType){
			var options = {
				type: type,
				dataType: "json",
				url: "echo.php",
				data: { 
					hello: "world"
				success: function(response){
			if (contentType) options.contentType = "application/json; charset=utf-8";

				send("get", false);
				send("get", true);
				send("post", false);
				send("post", true);



Change History (1)

comment:1 Changed 11 years ago by timmywil

Component: unfiledajax
Priority: undecidedlow
Resolution: invalid
Status: newclosed

I don't think this is an issue with jQuery. The data should be a valid json string if that is the contentType being used. In this case, I don't think sending the contentType is necessary.

Note: See TracTickets for help on using tickets.