The basic-ajax and JSON for the actual project of jquery and JavaScript (3)

Source: Internet
Author: User

I. What is JSON data?

A lightweight format for data interchange. In practice, you know how to use it.

Software development I think it's a process that uses and then knows its principles.

Examples are as follows:

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "Utf-8" />        <Scripttype= "Text/javascript"src= "Js/jquery-1.11.0.js" ></Script>        <Scripttype= "Text/javascript">                //define an array        varjsonstudents=[]; //creating a JSON object in an array         for(varI=0; I<5; I++)        {          varJsonobj={name:"', no:"'}; Jsonobj.name='Student_'+i.tostring (); Jsonobj.no='Current_no_'+i.tostring ();        Jsonstudents.push (Jsonobj); }                //Create your own HTML string based on a JSON object        varFormatrow=function(obj) {varrowhtml="<tr><td>"+obj.no+"</td>"                        +"<td>"+Obj.name+"</td></tr>"; returnrowhtml;                }; //CREATE table, based on data list        varcreatetable=function(){            for(varI=0; I<5; I++)            {              varrowhtml=Formatrow (Jsonstudents[i]); $("Table"). Append (rowhtml);                }        }; </Script>        <title></title>    </Head>    <Bodyonload= "createtable ()">        <Table>            <TR>                <th>Number</th>                <th>Name</th>            </TR>        </Table>    </Body></HTML>

Two. What is Ajax and how to use it?

Ajax, what is specific, you can check the data of the brain, the personal feel in fact a request, similar to what we talk to sister, Sister is the same as you, you and others said the first sentence, is sent a request, the other side with you reply to a word, called the return data, we can listen to understand, this is called data analysis, Then you can deal with their own happy chat with the sister.

Requests in the development of the Web site, return data, can be a file can be a picture can be a string can be a value of JSON object. Wait a minute.

Front-end UI, do not need to care about the background code implementation, just need to know how to handle the data request how to send, understand the reason.

First to analyze the blog Park Landing, to understand the request and return data:

When you log in, a login request is sent to the server, and the server returns you the data.

{"Success": false, "message": "The user does not exist"}

The wording of the AJAX request is deterministic, parameters and URLs are indeterminate, and Ajax has other option settings, such as synchronous asynchronous, or cache.

The basic wording is as follows:

$.ajax ({             url:url,/////Request address             data:para,//Some parameter information accompanying the request             DataType: "JSON",             success:function (data) {                 ///Request execution succeeds, execute the method, parameter is data passed by the server            }        });

Description

No matter how complex the JSON data is, as long as the concept of objects and arrays is divided, {} is wrapped up as a complete object, [] wrapped up in an array, [[],[],[]] what is this?

[{},{},{},[] ] ?

The analysis is that the array contains 3 elements and 3 elements are []. The back one is that the array object contains 4 elements, 4 elements, 3 JSON objects, and one data element.

The basic-ajax and JSON for the actual project of jquery and JavaScript (3)

Related Article

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.