ajax--receiving server-side response data

Source: Internet
Author: User
Tags xml parser

* Receive server-side response data

* Use the ResponseText property of the XMLHttpRequest core object

* This property can only receive text (HTML) formatting

* Questions

* Parsing process is more complex (split)

* Easy to make mistakes when splitting or stringing

* XML format

* Basic Content

* Differences between HTML, XHTML, DHTML, and XML

* HTML is the page-element defines the case

* XHTML is strictly HTML-the element defines lowercase

* dhtml-bom| Dom

* XML-configuration file | data format

* XML file with the extension ". xml"

* XML is defined in much the same way as HTML

* Elements of HTML are predefined

* XML allows for custom elements

* Version of XML

* Version 1.0-Current unique version

* Version 1.1-almost no one uses

* Note

* version will not be updated again

* The role of XML

* As data format-store data

* XML syntax

* Disclaimer

<?xml version= "1.0" encoding= "UTF-8"?>

* Version-sets the current edition of the XML file

* Encoding-sets the encoding of the current XML file

* Note-appears on 0 rows and 0 columns

* Define Elements

* Root element

* Must be the start tag

* You can define only one

* Define Elements

* Element names can be customized

* Classification

* Start tag or single label

* Define Attributes

* Define Annotations

* Practice-Define province and city information using XML files

* How to define all can, conform to XML syntax can

* Determines how easy it is to use JavaScript parsing later

* DOM parsing xml

* Parser to create XML

function Parsexml (XML) {

Declares the DOM object after parsing the XML

var xmldoc = null;

According to the different browser

if (window. Domparser) {

Other browsers

var parser = new Domparser ();

xmldoc = parser.parsefromstring (XML, "Application/xml");

}else{

IE browser

xmldoc = new ActiveXObject ("Microsoft.XMLDOM");

Xmldoc.async = false;

Xmldoc.loadxml (XML);

}

return xmldoc;

}

* Parsing XML is consistent with parsing HTML

* Rarely use Byid and byname two methods

* Note

* Browser does not allow external XML files to be read

* Browser parsing strings that conform to XML format

* XML format in AJAX

* Requested data format-XML

* How the client constructs data in a format that conforms to XML

* Built data type-string type

* The contents of the string conform to the syntax requirements of XML format

* How the server receives data in an XML-compliant format

* Receive client request data-string type

* PHP integrates DOM-related content

* DOMDocument class

* DomElement Class

* Domnode Class

* Response Data Format-XML

* Server-side how to build data in XML-compliant format

* Set the server-side response header "Content-type" value to "Text/xml"

* Build data content that conforms to XML format

* Build String content manually

* Methods for DOMDocument objects

* LoadXML (String that conforms to XML format);

* SaveXML () method to respond

* How the client receives data in a format that conforms to XML

* Receive using the Responsexml property of the XMLHttpRequest object

* The XML DOM object is received (no parsing is required using an XML parser)

* Parsing an XML DOM object directly using the DOM

* Exercise-two-level linkage (server-side response data format is in XML format)

* JSON format

* Basic Content

* Json-javascript Object Notation (JS native support)

* JSON data format originated from JavaScript

* Features

* Easy for programmers to read and write

* Easy computer parsing and generation

* JSON is currently one of the most widely used data formats on the Web

* Structure of JSON

* Array-arrays

* Object-Objects

* Supported data types

* String Strings

* Number Value

* Boolean-true|false

* Object

* Array

* NULL

* JSON format in Ajax

* Request format is JSON

* Client sends data requested in JSON format to server side

* Build a string that conforms to the JSON format

* Ensure that the string is defined using single quotation marks (double quotes inside)

* Server-side receive JSON-formatted data

* Receive client-side data

* Parsing using the Json_decode () function

Json_decode ($json, True)

* Response format is JSON

* Server-side sends the response to the client in JSON-formatted data

* Use the Json_encode () function to convert a PHP variable (array) into a JSON-formatted string

* Client receives JSON-formatted data

* Receive using the ResponseText property of the XMLHttpRequest object

* No Responsejson attribute

* Use the Eval () function to convert

* Job-complete two-level linkage using JSON format

* Advantages and disadvantages of HTML (text format), XML format, and JSON format

* HTML format

* Advantages-Simple

* Disadvantages-Complex analysis

* XML format

* Advantages-Easy to build complex data

* Disadvantages-build, parse complex

* JSON format

* Advantages-Lightweight

* Disadvantages-Possible conversion failure

* Review Content

* DOM-independent of any development language

* Classification of DOM

* DOM CORE

* DOM HTML

* DOM XML

* DOM CSS

* DOM API

* Get elements

* Create elements

* Replace Element

* Delete Element

* Insert Element

* ...

*

ajax--receiving server-side response data

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.