#13758 closed bug (notabug)
Cannot set content-type to 'application/json' in jQuery.ajax
Reported by: | KiranKumarT | Owned by: | KiranKumarT |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I have the exactly same issue as shown in the below link
Please let me know what the issue is.
I am using JQuery Version 1.9.1
Change History (8)
comment:2 follow-up: 3 Changed 10 years ago by
Owner: | set to KiranKumarT |
---|---|
Status: | new → pending |
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!
Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists—you may need to change this to a specific version depending on the test case.
To get you started, use the appropriate boilerplate:
- jQuery 1.x http://jsfiddle.net/FrKyN/
- jQuery 2.x http://jsfiddle.net/VUp3e/
Open the link and click to "Fork" (in the top menu) to begin.
Also, please read:
- http://blog.jquery.com/2013/03/01/jquery-2-0-beta-2-released/
- http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/
Additional resources:
- Won't Fix: http://contribute.jquery.org/wont-fix/
- CLA: http://contribute.jquery.org/CLA/
- Style Guide: http://contribute.jquery.org/style-guide/js/
comment:3 Changed 10 years ago by
Status: | pending → new |
---|
The link that I have provided do have fiddler information also.
But for reference I am again providing it here.
When I have this code
$.ajax({
type: 'POST',
contentType: "application/json",
url: 'http://localhost:16329/Hello',
data: { name: 'norm' },
dataType: 'json'
});
in Fiddler I can see following raw request
POST http://localhost:16329/Hello HTTP/1.1
Host: localhost:16329[[BR]]
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101
Firefox/10.0.2
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:14693/WebSite1/index.html[[BR]]
Content-Length: 9
Origin: http://localhost:14693[[BR]]
Pragma: no-cache
Cache-Control: no-cache
name=Kiran
But what I'm trying is to set content-type from application/x-www-form-urlencoded to application/json. But this code
$.ajax({
type: "POST",
contentType: "application/json",
url: 'http://localhost:16329/Hello',[[BR]] data: { name: 'norm' },
dataType: "json"
});
Generates strange request (which I can see in Fiddler)
OPTIONS http://localhost:16329/Hello HTTP/1.1
Host: localhost:16329[[BR]]
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Origin: http://localhost:14693[[BR]]
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Pragma: no-cache
Cache-Control: no-cache
In the first inputs If I get Content-Type: application/json; charset=UTF-8 instead of Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Then every thing will work properly.
By tomorrow Morning Indian Standard Time I will provide my Fiddler information.
comment:4 follow-ups: 5 6 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
This really does belong at StackOverflow, it's not a bug report it's a request for programming help.
comment:5 Changed 10 years ago by
No Its not a programming help. jQuery doesnot provide the correct Content-Type in Firefox.
It is working fine in IE and Chrome
comment:6 Changed 10 years ago by
Replying to dmethvin:
This really does belong at StackOverflow, it's not a bug report it's a request for programming help.
Please look at the StackOverFlow link that I have provided.. It is also mention the issue with out solution.
It is working fine in IE and Chrome where as in Firefox the content-type is not provided correctly. Is this JQuery issue or Firefox issue!!!!
comment:7 follow-up: 8 Changed 10 years ago by
Generates strange request (which I can see in Fiddler)
OPTIONS http://localhost:16329/Hello HTTP/1.1
Origin: http://localhost:14693[[BR]]
You're making a cross-domain request against your own localhost, that's why the OPTIONS is occurring.
comment:8 Changed 10 years ago by
Ok dmethvin. Thanks for your help. I will try keeping the code in live then will get back if needed.
Kiran.
The situation exactly is:
When I write code like below:
$.ajax({
I am getting Content-Type: application/x-www-form-urlencoded; charset=UTF-8 instead of expecting Content-Type: application/json; charset=UTF-8
I have tried with various options with processdata: true/false and crossDomain: true/false and also I remove these two and checked.
The above scenario is working fine in IE 8/9/10 and Chrome when we add Content-Type: application/json; charset=UTF-8 to the above code.
Please advise.