Should I still be using jquery .getJson in 1.4.2?
Posted
by chobo2
on Stack Overflow
See other posts from Stack Overflow
or by chobo2
Published on 2010-05-18T20:25:45Z
Indexed on
2010/05/18
21:20 UTC
Read the original article
Hit count: 193
asp.net-mvc
|jQuery
Hi
I was looking at the 14 days of jquery
http://jquery14.com/day-01/jquery-14
and I saw this and it got me to wondering is there a point to use getJson anymore?
JSON and script types auto-detected by content-type (jQuery.ajax Documentation, Commit 1, Commit 2)
If the response to an Ajax request is returned with a JSON mime type (application/json), the dataType defaults to “json” (if no dataType is specified). Additionally, if the response to an Ajax request is returned with a JavaScript mime type (text/javascript or application/x-javascript) , the dataType defaults to “script” (if no dataType is specified), causing the script to automatically execute.
First I can see such a huge benefit of this. In jquery 1.3 I came to a situation where in some cases I would return a partial view and some cases I would return a json result (asp.net mvc).
It worked in firefox but in no other browser and one of the problems was I basically had to tell jquery to either do json or text/html.
With it automatically detecting I could get away with this. Anyways I found a solution around this at that time.
So now it just makes me wonder if there is any point to using GetJson.
I am also unsure how to set these JavaScript mime types? I am assuming that if you return a JsonResult from asp.net mvc it will set it. but I am not sure if I was just sending a text result if it would be set( I am not sure if ContentResult would set this).
© Stack Overflow or respective owner