jquery obtains JSON-formatted files directly through the Getjson () function:
First: The contents of the obtained file must conform to the JSON format:
{"Property": "Property value" ....} The format;
Otherwise, this method is not accessible to the content;
The code format is as follows :
$ (function () {$.getjson ("Datagrid_data2.json"),//loaded JSON file, specifying the specific directory function (JSON) {//Execute successful callback function columns = JSON; });});
Asynchronously loads the file via jquery's Ajax, GET, Post methods:
The data that is loaded by this asynchronous method may not be in pure JSON format, but can be other formats;
If it is JSON format data, specify datatype: "JSON", you can directly get to the JS object;
If the data is not in JSON format, you can specify datatype: "text", "html" ...
-
-
$.ajax ({ url : "ColumnName.json",// Requested resource datatype: "Text", //returned result type: Text success : function (JSON) { //performs a successful callback function Console.info (JSON); //Console output var arr = eval ("(" + json + ")"); //if it is text, convert it to Object init (arr);
});
$.get ():
Note the order of the parameters passed, the order is not correct, and will fail (can not write some but the order must be)
$.get ("Columnname.json",//Access resource {},//passed parameter function (JSON) {///Success callback function var arr = eval ("(" + JSON + ")"); Convert the received parameter to object}, "text"//Return the result type (XML, HTML, script, JSON, text, _default));
$.post ():
Similar to the Get method;
This article is from the "Breeze" blog, be sure to keep this source http://fuyanchao.blog.51cto.com/3752384/1608981
jquery accesses JSON, JS and other files