jquery accesses JSON, JS and other files

Source: Internet
Author: User

  1. jquery obtains JSON-formatted files directly through the Getjson () function:

    1. First: The contents of the obtained file must conform to the JSON format:

      1. {"Property": "Property value" ....} The format;

    2. Otherwise, this method is not accessible to the content;

    3. The code format is as follows :

      1. $ (function () {$.getjson ("Datagrid_data2.json"),//loaded JSON file, specifying the specific directory function (JSON) {//Execute successful callback function columns = JSON; });});
  2. Asynchronously loads the file via jquery's Ajax, GET, Post methods:

    1. The data that is loaded by this asynchronous method may not be in pure JSON format, but can be other formats;

    2. If it is JSON format data, specify datatype: "JSON", you can directly get to the JS object;

    3. If the data is not in JSON format, you can specify datatype: "text", "html" ...

      1. $.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);  
           }); 
    4. $.get ():

      1. Note the order of the parameters passed, the order is not correct, and will fail (can not write some but the order must be)

      2. $.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));
    5. $.post ():

      1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.