您的位置:首页 > 理论基础 > 计算机网络

ajax xml_AJAX XML http

2020-08-02 15:25 183 查看

ajax xml

AJAX stands for asynchronous JavaScript and XML. It's a modern way to structure and build web applications using the built-in AJAX engine inside the browser. One of the key features of AJAX is the XMLHttpRequest object through which we can do a whole bunch of cool stuff with respect to interacting with a third party application or an API.

AJAX代表异步JavaScript和XML。 这是使用浏览器中内置的AJAX引擎构建和构建Web应用程序的现代方法。 AJAX的主要功能之一是XMLHttpRequest对象,通过该对象,我们可以在与第三方应用程序或API交互方面做很多很棒的事情。

Using the XMLHttpRequest object we can update the content dynamically on the web page.

使用XMLHttpRequest对象,我们可以在网页上动态更新内容。

Let's see how we can create an XMLHttpRequest object?

让我们看看如何创建XMLHttpRequest对象?

var xhttp = new XMLHttpRequest();
console.log(xhttp);
[/code]

Output

输出量

XMLHttpRequest {onreadystatechange: null, readyState: 0, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
[/code]

As you can see this object has loads of methods and properties available for use. Let's first look at some common properties,

如您所见,该对象具有大量可供使用的方法和属性。 让我们先来看一些常见的属性,

  1. readyState:

    readyState

    This property defines the current state of our object. This state can take certain values based on our interaction with the URL and based on those values we can determine what to do next.

    此属性定义对象的当前状态。 根据我们与URL的交互,此状态可以采用某些值,并根据这些值可以确定下一步要做什么。

    For example, a value of 0 indicates that the request has not been initialized yet. A value of 1 indicates the request is set up but not sent just yet. A value of 2 tells you that your request has been sent. In case the request is still in the process of being sent over, it gets a value of 3 and finally on successful completion of the request the readyState takes a value of 4. We'll see these in detail when we look at the methods.

    例如,值为0表示请求尚未初始化。 值1表示已建立请求,但尚未发送。 值为2表示您的请求已发送。 如果请求仍在发送过程中,则它的值为3,最后在成功完成请求后,readyState的值为4。我们将在查看方法时详细介绍这些内容。

  2. onreadystatechange:

    onreadystatechange

    Since the readyState takes 4 values, these values are in the order in which the request gets processed. At least we can logically assume so. When these values change, this event is triggered and we can use this to fire a function. This tells us that ok, go ahead and make some request for some data.

    由于readyState取4个值,所以这些值按处理请求的顺序排列。 至少在逻辑上我们可以这样假设。 当这些值更改时,将触发此事件,我们可以使用它来触发一个函数。 这告诉我们,好的,继续请求一些数据。

  3. responseText:

    responseText

    This is the string that is returned as the response from the request.

    这是作为请求响应返回的字符串。

  4. responseXML:

    responseXML

    This returns the response in XML data format.

    这将返回XML数据格式的响应。

  5. status:

    状态

    This property attaches the status returned after the request is made like 400, 404, etc that you often see on web sites.

    此属性附加在发出请求后返回的状态,例如您经常在网站上看到的400、404等。

  6. statusText:

    statusText

    This attaches the status string returned like Not found, OK associated with a certain status code.

    这将附加返回的状态字符串,如“未找到,确定”与某个状态代码关联。

Now let's look at the most commonly used methods available,

现在,让我们看一下最常用的方法,

  1. abort():

    abort()

    This method cancels or aborts the request as the name suggests.

    顾名思义,此方法取消或中止请求。

  2. open():

    open()

    This method specifies the request that is to be sent and ahs 4 parameters: the type of request like

    此方法指定要发送的请求和4个参数:请求的类型,例如

    GET, PUT, POST, etc, the endpoint or URL at which we're hitting or making the request, a boolean indicating whether the request should be handled synchronously or asynchronously and an optional username and password.

    GETPUTPOST等,我们在其中命中或发出请求的端点或URL,一个布尔值,指示是应同步还是异步处理请求,以及可选的用户名和密码。

  3. send():

    send()

    Used for the request content. We can directly use

    用于请求内容。 我们可以直接使用

    send() for sending GET requests and pass in a string as a parameter to send a POST request.

    send()用于发送GET请求,并传递一个字符串作为参数来发送POST请求。

翻译自: https://www.includehelp.com/ajax/ajax-xml-http.aspx

ajax xml

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: