search
HomeWeb Front-endJS TutorialUnderstanding of xmlHttp object methods and properties_Basic knowledge

1  客户端可以通过xmlHttp对象(MSXML2.XMLHTTP.3.0)向http服务器发送请求并使用文档对象模型(DOM)处理回应。

1.1 我的理解:

  1. 用户的每次操作,都会有数据产生。
  2. 通过DOM或者JS编写对数据进行封装,或者浏览器自身对http协议的一些数据进行封装。
  3. 通过xmlHttp对象的一些方法,传入数据参数,向http服务器发送请求。
  4. 返回结果通过DOM进行处理。

2  xmlHttp对象的成员。

2.1 属性

  1. onreadystatechange:readyState属性值发生改变时,触发的事件处理句柄。

例子:xmlHttp.onreadystatechange = functionHandler;

   function functionHandler() {

if(xmlHttp.readyState == 4) {

alert("readyState状态为4时,弹出此窗口!!!");

}

  }

//句柄只有方法名称,没有这对“()”括号。赋值时要注意理解。

  1. readyState:这个属性表示状态;总共有五种状态:

0 (未初始化)

对象已建立,但是尚未初始化(尚未调用open方法)

1 (初始化)

对象已建立,尚未调用send方法

2 (发送数据)

send方法已调用,但是当前的状态及http头未知

3 (数据传送中)

已接收部分数据,因为响应及http头不全,这时通过responseBody和responseText获取部分数据会出现错误,

4 (完成)

数据接收完毕,此时可以通过通过responseBody和responseText获取完整的回应数据

// Because xmlHttp is written in a fixed way, so each step will be accompanied by a change of state, so the event handler is always monitored , execute the corresponding logic.

Code execution order:

var xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");

xmlHttpReq.open("GET", "http://localhost/test.xml", false);

xmlHttpReq.send();

alert(xmlHttpReq.responseText);

2.2 Method

  1. open(Method, Url, Syn, User, Password);

When you create a new xmlHttp object, you actually create a http request.

This method specifies the request method(GET/POST/PUT/PROPFIND), URL, asynchronous(The default is true), verification information.

When

adopts the asynchronous method (true), the callback function specified by the onreadystatechange attribute will be called when the state changes.

  1. send();

The synchronous or asynchronous mode of this method depends on the Syn parameter in the open method, if Syn = = false, this method will wait for the request to complete or timeout before returning, if Syn == true, this method will return immediately.

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
如何在Python中获取整数字面量属性而不是SyntaxError?如何在Python中获取整数字面量属性而不是SyntaxError?Aug 20, 2023 pm 07:13 PM

TogetintliteralattributeinsteadofSyntaxError,useaspaceorparenthesis.TheintliteralisapartifNumericLiteralsinPython.NumericLiteralsalsoincludesthefollowingfourdifferentnumericaltypes−int(signedintegers)−Theyareoftencalledjustintegersorints,arepositiveo

深入理解Go语言中的类方法和对象方法深入理解Go语言中的类方法和对象方法Apr 03, 2024 pm 09:27 PM

Go语言中没有传统的类和对象,而是使用struct和方法。类方法绑定到类型,用于操作整个类型。对象方法绑定到对象实例,用于操作特定实例。两者接收者不同:类方法的接收者是类型,而对象方法的接收者是对象实例指针。命名约定也存在差异:类方法首字母大写,对象方法首字母小写。

如何在Java中使用Gson重命名JSON的属性?如何在Java中使用Gson重命名JSON的属性?Aug 27, 2023 pm 02:01 PM

Gson@SerializedName注释可以序列化为JSON,并将提供的名称值作为其字段名称。此注释可以覆盖任何FieldNamingPolicy,包括可能已在Gson实例上设置的默认字段命名策略。可以使用GsonBuilder类设置不同的命名策略。语法@Retention(value=RUNTIME)@Target(value={FIELD,METHOD})public@interfaceSerializedName示例importcom.google.gson.annotations.*;

Python的dir()函数:查看对象的属性和方法Python的dir()函数:查看对象的属性和方法Nov 18, 2023 pm 01:45 PM

Python的dir()函数:查看对象的属性和方法,需要具体代码示例摘要:Python是一种强大而灵活的编程语言,其内置函数和工具为开发人员提供了许多方便的功能。其中一个非常有用的函数是dir()函数,它允许我们查看一个对象的属性和方法。本文将介绍dir()函数的用法,并通过具体的代码示例来演示其功能和用途。正文:Python的dir()函数是一个内置函数,

Win11磁盘属性未知怎么办Win11磁盘属性未知怎么办Jul 03, 2023 pm 04:17 PM

  Win11磁盘属性未知怎么办?近期Win11用户在电脑的使用中,发现系统出现提示磁盘错误的情况,这是怎么回事儿呢?而且应该如何解决呢?很多小伙伴不知道怎么详细操作,小编下面整理了Win11磁盘出错的解决步骤,如果你感兴趣的话,跟着小编一起往下看看吧!  Win11磁盘出错的解决步骤  1、首先,按键盘上的Win+E组合键,或点击任务栏上的文件资源管理器;  2、文件资源管理器的右侧边栏,找到边右键点击本地磁盘(C:),在打开的菜单项中,选择属性;  3、本地磁盘(C:)属性窗口,切换到工具选

C++ 成员函数详解:对象方法在 OOP 中的角色与职责C++ 成员函数详解:对象方法在 OOP 中的角色与职责Apr 30, 2024 am 09:33 AM

成员函数是OOP中对象的方法,定义了特定行为。它们可以是:访问函数(获取/设置属性)、操作函数(执行操作)、构造函数(创建对象)和析构函数(销毁对象)。通过成员函数,我们可以操作和修改对象,实现复杂的软件设计。

使用Vue.set函数实现动态添加属性的方法和示例使用Vue.set函数实现动态添加属性的方法和示例Jul 24, 2023 pm 07:22 PM

使用Vue.set函数实现动态添加属性的方法和示例在Vue中,如果我们想要动态地添加一个属性到一个已经存在的对象上,通常会使用Vue.set函数来实现。Vue.set函数是Vue.js提供的一个全局方法,它能够在添加属性时保证响应式更新。本文将介绍Vue.set的使用方法,并提供一个具体的示例。首先,在Vue中,我们通常会使用data选项来声明响应式的数据。

pageXOffset属性在JavaScript中的作用是什么?pageXOffset属性在JavaScript中的作用是什么?Sep 16, 2023 am 09:17 AM

如果您想获取文档从窗口左上角滚动到的像素,请使用pageXoffset和pageYoffset属性。对水平像素使用pageXoffset。示例您可以尝试运行以下代码来了解如何在JavaScript中使用pageXOffset属性-现场演示<!DOCTYPEhtml><html>&nbsp;&nbsp;<head>&nbsp;&nbsp;&nbsp;<style>&nbsp;&nbsp;&

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),