Side navigation
#10534 closed bug (invalid)
Opened October 19, 2011 01:58PM UTC
Closed October 19, 2011 03:05PM UTC
Last modified March 14, 2012 07:57AM UTC
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: |
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>
Attachments (0)
Change History (1)
Changed October 19, 2011 03:05PM UTC by comment:1
component: | unfiled → ajax |
---|---|
priority: | undecided → low |
resolution: | → invalid |
status: | new → closed |
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.