开发者

Should I still be using jquery .getJson in 1.4.2?

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 speci开发者_开发知识库fied), 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).


It is still useful as a shorthand method if all you need is the functionality offered by .getJson(). Personally, I usually end up using .ajax() for its customizability most of the time anyway.

EDIT: J-P brings up a good point in the comments that as a shorthand method, with autodetection of MIME types, .getJson is essentially rendered redundant to .get since $.getJson(a,b) would do the exact same thing as $.get(a,b).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜