Should I use jquery.getJson in 1.4.2?

I watched 14 days jquery

http://jquery14.com/day-01/jquery-14

And I saw this, and I wondered if it makes sense to use getJson?

JSON and script are automatically recognized by content-type (jQuery.ajax Documentation, Commit 1, Commit 2)

If the response to the Ajax request is returned with the MIM JSON type (application / json), the dataType defaults to "json" (if no data of the type are specified). In addition, if the response to the Ajax request is returned with a JavaScript mime type (text / javascript or application / x-javascript), the default dataType is β€œscript” (if there is no dataType), resulting in a script to automatically execute.

At first I see such a huge benefit from this. In jQuery 1.3, I came to a situation where in some cases I would return a partial view, and in 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 that I basically had to set jquery to either json or text / html.

With it, it is automatically detected that I could handle this. In any case, I found a solution around this at the time.

So now I'm just wondering if it makes sense to use GetJson.

I'm also not sure how to set these mime JavaScript types? I assume that if you return JsonResult from asp.net mvc, it will install it. but I'm not sure if I'm just sending a text result if it is set (I'm not sure if ContentResult would set this).

+4
source share
1 answer

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 customization most of the time.

EDIT: JP gives a good point in the comments, which, as a shortened method, with auto-detection of MIME types, .getJson essentially seems to be redundant .get, since $ .getJson (a, b) will do the same as $ .get ( a, b).

+2
source

Source: https://habr.com/ru/post/1310160/


All Articles