How to load local json file using jquery

version added: url <, data > <, success > )
Data that is sent lớn the vps is appended lớn the URL as a query string. If the value of the data parameter is a plain object, it is converted to a string và url-encoded before it is appended lớn the URL.

Bạn đang xem: How to load local json file using jquery

Most implementations will specify a success handler:

Using this structure, the example loops through the requested data, builds an unordered list, & appends it to the body.

The success callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure và parsed using the $.parseJSON() method. It is also passed the text status of the response.

As of 1.5, the success callback function receives a "jqXHR" object (in 1.4, it received the XMLHttpRequest object). However, since JSONP và cross-domain GET requests vì chưng not use XHR, in those cases the jqXHR và textStatus parameters passed to the success callback are undefined.

Xem thêm: Thanh Lý Xe Đạp Fixed Gear Cũ, ¤ Xe Đạp Fixed Gear Single Đùm Thắng

Important: As of 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript's object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes. For details on the JSON format, see


If the URL includes the string "callback=?" (or similar, as defined by the server-side, the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

The jqXHR Object

As of 1.5, all of's Ajax methods return a superset of the XMLHTTPRequest object. This XHR object, or "jqXHR," returned by $.getJSON() implements the Promise interface, giving it all the properties, methods, và behavior of a Promise (see Deferred object for more information). The jqXHR.done() (for success), (for error), và jqXHR.always() (for completion, whether success or error; added in 1.6) methods take a function argument that is called when the request terminates. For information about the arguments this function receives, see the jqXHR Object section of the $.ajax() documentation.

The Promise interface in 1.5 also allows's Ajax methods, including $.getJSON(), to lớn chain multiple .done(), .always(), và .fail() callbacks on a single request, and even lớn assign these callbacks after the request may have completed. If the request is already complete, the callback is fired immediately.