Get the App
SLTechnology News&Howtos  ›  Development  › 

Introduction to the examples of common functions in AJAX

Shulou Source: shulou.com Published: 2022-06-03 16:41:25 10月03日 Update

This article mainly explains the "introduction of examples of common functions in AJAX". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the introduction of examples of common functions in AJAX".

Create XMLHTTP objects to distinguish IE,Mozilla browsers

The code is as follows:

Function getRequest () {

Http_request = false

If (window.XMLHttpRequest) {

/ / for browsers such as Mozilla, Netscape, Safari, create a XMLHttpRequest

Http_request = new XMLHttpRequest ()

If (http_request.overrideMimeType) {

/ / if the header of the server response is not text/xml, you can call other methods to modify the header

Http_request.overrideMimeType ('text/xml')

}

} else if (window.ActiveXObject) {

/ / for Internet Explorer browsers, create a XMLHttpRequest

Try {

Http_request = new ActiveXObject ("Msxml2.XMLHTTP")

} catch (e) {

Try {

Http_request = new ActiveXObject ("Microsoft.XMLHTTP")

} catch (e) {}

}

}

Return http_request

}

/ / obtain the responseText of Url

The code is as follows:

Function getResponseText (url)

{

Http_request=getRequest ()

Http_request.open ('GET', url, false)

Http_request.send (null)

If (http_request.readyState = = 4)

{

/ / receive a complete server response

If (http_request.status = = 200) {

/ / the value OK of the HTTP server response

Requestdoc = http_request.responseText

/ / write the string returned by the server to the area of the page where ID is message

}

Else {

Requestdoc = http_request.status

}

}

Return requestdoc

}

/ / obtain the responseXML of Url

The code is as follows:

Function getResponseText (url)

{

Http_request=getRequest ()

Http_request.open ('GET', url, false)

Http_request.send (null)

If (http_request.readyState = = 4)

{

/ / receive a complete server response

If (http_request.status = = 200) {

/ / the value OK of the HTTP server response

Requestdoc = http_request.responseXML

/ / write the string returned by the server to the area of the page where ID is message

}

Else {

Requestdoc = http_request.status

}

}

Return requestdoc

}

Thank you for your reading, the above is the content of "introduction of examples of common functions of AJAX". After the study of this article, I believe you have a deeper understanding of the introduction of examples of common functions of AJAX, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Server service function instance common use code browser learning browsing content region character string page object that is idea situation article method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi Redmi Docker Microsoft