$ .get (u, d, c, "JSON") vs $ .getJSON (u, d, c)

I usually use $.get()it $.post()for all my asynchronous calls, but they usually qualify with the last parameter, which is "JSON", which indicates that I expect to process JSON data in my callback.

Is there any benefit of using $.get([url],[data],[callback],"JSON")over $.getJSON([url],[data],[callback])? Is it nothing more than to include the final parameter, an explicit declaration of the return type?

+3
source share
2 answers

No difference. This is obvious from the jQuery source . I use getJSONfor all cross domain calls and getwhen calls follow the same origin policy.

getJSON: function( url, data, callback ) {
  return jQuery.get(url, data, callback, "json");
}
+11
source

As @Chandra noted, this is a convenient method. I also checked the source, and it just calls $.get. Thus, the only value of $.getover $.getJSONis one method call. However, since this seems clearer, I would say that use $.getJSONshould be preferred$.get

+2
source

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


All Articles