Bug Tracker

Modify

Ticket #10534 (closed bug: invalid)

Opened 19 months ago

Last modified 15 months ago

POST Ajax and contentType sends no data.

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

Description

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:

<?php

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

?>

---

Source of index.html:

<html>
<body>

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


	<h1>POST</h1>
	<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>-->
	<script>

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

		$(function(){
			$("#get-without").click(function(){
				send("get", false);
			});
			$("#get-with").click(function(){
				send("get", true);
			});
			$("#post-without").click(function(){
				send("post", false);
			});
			$("#post-with").click(function(){
				send("post", true);
			});
		});

	</script>

</body>
</html>

Change History

comment:1 Changed 19 months ago by timmywil

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to ajax

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.