45

Possible Duplicate:
Difference Between $.getJSON() and $.ajax() in jQuery

super simple question.... between .getjson and .ajax() json which is faster?

considering retrieving and parsing data.

Much thanks.

Community
  • 1
  • 1
Jerry Harrison
  • 473
  • 1
  • 5
  • 8

4 Answers4

45

.getjson() calls .ajax(), so they should be equivalent.

colinmarc
  • 2,421
  • 1
  • 22
  • 34
  • 15
    Not entirely correct. `.getJSON()` parses the JSON string into an Object, whereas `.ajax()` returns a String that you would have to parse as in `obj=jQuery.parseJSON(data)` – Apuleius Aug 20 '15 at 14:58
  • 5
    @Apuleius not necessarily,IMHO if you specify "dataType: json" the returned data will be parsed into Object automagically. – benjaminz Dec 13 '16 at 14:15
  • looks like .getJson caches by default and doesn't have a direct cache true/false option like .ajax. https://stackoverflow.com/questions/13391563/how-to-set-cache-false-for-getjson-in-jquery – Michael Jan 06 '20 at 22:17
41

Same thing. getJSON() is a shorthand for .ajax(..) with specific parameters.

To quote the documentation of .getJSON():

This is a shorthand Ajax function, which is equivalent to:

   $.ajax({
      url: url,
      dataType: 'json',
      data: data,
      success: callback
    });
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
13

I had a similiar question, and wanted to point out the following documentation in JQuery.ajax:

The $.ajax() function underlies all Ajax requests sent by jQuery. It is often unnecessary to directly call this function, as several higher-level alternatives like $.get() and .load() are available and are easier to use. If less common options are required, though, $.ajax() can be used more flexibly.

cmcginty
  • 113,384
  • 42
  • 163
  • 163
5

jQuery.getJSON() uses the same jQuery.ajax() call finally, so there are no speed differences.

KARASZI István
  • 30,900
  • 8
  • 101
  • 128