search
HomeBackend DevelopmentXML/RSS Tutorialajax xmlHttpRequest object

ajax xmlHttpRequest object

Feb 23, 2017 pm 02:56 PM
ajax

Please indicate the source when reprinting: ajax’s xmlHttpRequest object
The XMLHttpRequest object is the core of ajax. It has many properties, methods and events to facilitate script processing and control http request responses. If you have been using native javascript for development, you need to know this object very well when using ajax. If you use an encapsulation framework such as jquery, having a better understanding of it will also deepen your understanding of it. Ajax understanding.

The following is an introduction to some of its attributes:

1.readState attribute: When the xmlHttpRequest object is created, this attribute will tell you that the core object is created Finally, what state is it in and whether it can be accessed or processed? readState can be equal to 0, 1, 2, 3, 4; respectively, 0: the object has been created but not initialized (such as: int i;), 1: has Call the open() method of the object and prepare to send the request. 2: The send() method has been called to request, but no response was received. 3: Responding. 4: Completed the response and completed the reception of the httpResponse response.

          2.responseText attribute: Contains the text content of the http response received by the client. When readState is 0, 1 or 2, this attribute is an empty string. When it is 3, it is a partially received string. When it is 4, this attribute is the complete response information.

        3.responseXml attribute: Only when readyState=4 and the Content-Type type of the response header is specified as XML (text/xml or application/xml), the value of this attribute is an xml document. Otherwise, it is null. If the returned xml is in poor format or the response is not completed, the value of this attribute will also be null. It is used to describe the properties of the xmlHttpRequest object after parsing the xml document.

        4.status attribute: marked with http status code. This property can only be accessed when readyState=3 or 4, otherwise an exception will be thrown when obtaining this property.

          5.statusText attribute: The text marked with the http status code. This property can only be accessed when readyState=3 or 4, otherwise an exception will be thrown when obtaining this property.

The following is an introduction to one of its events: onreadystatechange event

Whenever the properties of readyState change, this event will be triggered, which is ajax The most frequently used core events in requests.

The following is an introduction to some methods:

1.open(): The xmlHttpRequest object is executed by calling the open(method, uri, async, username, password) method. Initialization work. After calling this method, an object that can be sent (send() method) is returned. method is a required parameter. According to the http specification, it can be GET, POST, PUT, DELETE and HEAD; uri is used to specify the server address requested by the xmlHttpRequest object, which can be a relative path or an absolute path, and will eventually be resolved into an absolute path; async Used to specify whether it is asynchronous, the default is true; if the server needs to verify the access user, then the two parameters of username and password can be used.

        2.send(): The send() method requests to send the parameters in the open() method, that is, it can only be called after the open() call, that is, send can be called after readState=1 (), before send() receives the response information, readyState=2, once send() receives the response information, readyState=3, until the final acceptance is completed, readyState=4. The send method takes an optional parameter, which can contain variable type data. For large. For most other data types, you should use setRequestHeader() to set the Content-Type before calling send(). Generally, send(null) is used to explicitly call this method. If the data type in send(data) is DOMString, the data is edited to utf-8. If it is Document, the encoding string specified by

data.xmlEncoding Rowize this data.

3.about(): You can pause the sending or receiving of an httpRequest request, and set the xmlHttpRequest object to the initialized state.

4.setRequestHeader(): Set the header information of the request. When readyState=1, you can call it after calling open(), otherwise you will get an exception.

.     5.setResponseHeader(): used to retrieve response header information. It can only be called when readyState=4 or 3, otherwise an empty string will be obtained. In addition, getAllResponseHeader() is used to obtain all httpResponse header information.

# and above are the contents of the XMLHTTPRequest object of Ajax. For more related content, please pay attention to PHP Chinese (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
RSS in XML: Unveiling the Core of Content SyndicationRSS in XML: Unveiling the Core of Content SyndicationApr 22, 2025 am 12:08 AM

The implementation of RSS in XML is to organize content through a structured XML format. 1) RSS uses XML as the data exchange format, including elements such as channel information and project list. 2) When generating RSS files, content must be organized according to specifications and published to the server for subscription. 3) RSS files can be subscribed through a reader or plug-in to automatically update the content.

Beyond the Basics: Advanced RSS Document FeaturesBeyond the Basics: Advanced RSS Document FeaturesApr 21, 2025 am 12:03 AM

Advanced features of RSS include content namespaces, extension modules, and conditional subscriptions. 1) Content namespace extends RSS functionality, 2) Extended modules such as DublinCore or iTunes to add metadata, 3) Conditional subscription filters entries based on specific conditions. These functions are implemented by adding XML elements and attributes to improve information acquisition efficiency.

The XML Backbone: How RSS Feeds are StructuredThe XML Backbone: How RSS Feeds are StructuredApr 20, 2025 am 12:02 AM

RSSfeedsuseXMLtostructurecontentupdates.1)XMLprovidesahierarchicalstructurefordata.2)Theelementdefinesthefeed'sidentityandcontainselements.3)elementsrepresentindividualcontentpieces.4)RSSisextensible,allowingcustomelements.5)Bestpracticesincludeusing

RSS & XML: Understanding the Dynamic Duo of Web ContentRSS & XML: Understanding the Dynamic Duo of Web ContentApr 19, 2025 am 12:03 AM

RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS Documents: The Foundation of Web SyndicationRSS Documents: The Foundation of Web SyndicationApr 18, 2025 am 12:04 AM

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

Decoding RSS: The XML Structure of Content FeedsDecoding RSS: The XML Structure of Content FeedsApr 17, 2025 am 12:09 AM

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

How to Parse and Utilize XML-Based RSS FeedsHow to Parse and Utilize XML-Based RSS FeedsApr 16, 2025 am 12:05 AM

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS Documents: How They Deliver Your Favorite ContentRSS Documents: How They Deliver Your Favorite ContentApr 15, 2025 am 12:01 AM

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor