#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: |
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 (1)
comment:1 Changed 11 years ago by
Component: | unfiled → ajax |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
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.