Ajax data Format

Source: Internet
Author: User
Tags json

On the server side Ajax is a language-independent technology. What server-side languages are used at the business logic level. When receiving data from the server side, those data must be sent in a format that the browser can understand. The server-side programming language can only return data in the following 3 formats:

Html transfer format

Since the returned data format is HTML, you can use the function innerHtml to insert the tag.

The htmltest.jsp code is as follows

 1 <%--2 Created by IntelliJ idea. 3 User:yin ' Zhao 4 date:2017/12/04 5 time:23:23 6 To change this template use File | Settings |
 File Templates.     7--%> 8 <%@ page contenttype= "Text/html;charset=utf-8" language= "java"%> 9  

Pages corresponding to hyperlinks (sspage.jsp, yy.html, yysspage.html)

1 
1 
1 

XML transfer format

The transfer format for XML needs to parse the JSP page into XML to get the label content and then join the page

 1 <%--2 Created by IntelliJ idea. 3 User:yin ' Zhao 4 date:2017/12/05 5 time:8:41 6 To change this template use File | Settings |
 File Templates.     7--%> 8 <%@ page contenttype= "Text/html;charset=utf-8" language= "java"%> 9  

XML files corresponding to hyperlinks (Ss.xml, Yy.xml, Ys.xml)

1 <?xml version= "1.0" encoding= "UTF-8"?>
2 <details>
3 <name>ss</name>
4 < Website>ss.com</website>
5 </details>
1 <?xml version= "1.0" encoding= "UTF-8"?>
2 <details>
3     <name>yy</name>
4     <website>yy.com</website>
5 </details>
1 <?xml version= "1.0" encoding= "UTF-8"?>
2 <details>
3     <name>ys</name>
4     <website>ys.com</website>
5 </details>

JSON transfer format

Transfer the data format to JSON first before the page needs to convert it to JSON format

<%--Created by IntelliJ idea. User:yin ' Zhao date:2017/12/04 time:23:23 to change this template use File | Settings |
    File Templates.
        --%> <%@ page contenttype= "Text/html;charset=utf-8" language= "java"%>  

JSON file corresponding to each hyperlink

1 {
2   "person": {
3     "name": "SS",
4     "website": "ss.com"
5   }
6}
1 {
2   "person": {
3     "name": "Ys",
4     "website": "ys.com"
5   }
6}
{"Person
  ": {
    "name": "yy",
    "website": "Yy.com"
  }
}

Advantages and disadvantages of various transmission formats

Advantages

1. HTML transfer format does not need JS parsing html code, good readability, HTML code and InnerHtml properties with high efficiency

2. XML is a common transport format that eliminates the need to force data into a well-defined format, and customizes the appropriate markup for the data, using the DOM to fully master the document

3. JSON is similar to XML but lighter than the other

Disadvantages

1. HTML is inappropriate if you need to update multiple parts of a document using Ajax

2. DOM parsing can be complex when a browser receives a longer XML document

3. JSON syntax is rigorous, the code is not suitable for reading

Applicable scenarios

1. If application does not need to share data with other programs, use HTML

2. If the data needs to be reused JSON has advantages in terms of performance and size

3. XML document is preferred when remote program is unknown







Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.