在ajax流程中需要帮助

时间:2022-08-25 02:09:08

http://www.ibm.com/developerworks/library/j-ajax1/ajax.gif

http://www.ibm.com/developerworks/library/j-ajax1/ajax.gif

I came across this flow, i would like to know certain things over this.

我遇到了这个流程,我想知道这方面的某些事情。

  1. What does Raise - > DOM Event do?
  2. 什么是Raise - > DOM事件吗?
  3. After creating an XMLHTTPRequest why do we create a callback function?
  4. 创建XMLHTTPRequest后,为什么要创建回调函数?
  5. Register callback... what does it do?
  6. 注册回调......它做了什么?
  7. Parse response into XML DOM?
  8. 将响应解析为XML DOM?
  9. Interogate response DOM?
  10. Interogate响应DOM?

Finally a basic question...

最后一个基本问题......

What does DOM contain and What does it do actually?

DOM包含什么?它实际上做了什么?

1 个解决方案

#1


1  

The DOM is an object representation of the HTML code. HTML documents are just simple text files, but it is often useful to consider one like it is a tree of elements. So, if your html contains <body><div>hello</div><div>world</div></body> then the DOM will have a "body" object that contains two "div" objects as children. It lets you examine and modify an HTML document in a program without having to do text parsing of the HTML code.

DOM是HTML代码的对象表示。 HTML文档只是简单的文本文件,但考虑它是一个元素树通常很有用。因此,如果您的html包含

hello
world ,那么DOM将有一个“body”对象,其中包含两个“div”对象作为子对象。它允许您在程序中检查和修改HTML文档,而无需对HTML代码进行文本解析。

  1. A DOM event is raised when the user interacts with an element of the DOM, so it's something like an "onclick" or "onkeypress" event. It will have an event handler, which is a function containing code to execute when the event occurs.

    当用户与DOM的元素交互时,会引发DOM事件,因此它类似于“onclick”或“onkeypress”事件。它将有一个事件处理程序,它是一个包含在事件发生时执行的代码的函数。

  2. Because the XmlHttpRequest is asynchronous. After the request is sent, the page will not wait for the response but instead will continue executing the rest of your code. The callback function waits for the response from the server and then executes. So your code to request data from the server should go in the event handler, and the code to process the data goes in the callback.

    因为XmlHttpRequest是异步的。发送请求后,页面不会等待响应,而是继续执行其余代码。回调函数等待来自服务器的响应然后执行。因此,从服务器请求数据的代码应该放在事件处理程序中,处理数据的代码将在回调中进行。

  3. This just tells the system that the callback function is to be called when the XmlHttpRequest gets data back from the server. If you had multiple XmlHttpRequests with different callbacks you would need to make sure each callback is registered to the right XmlHttpRequest.

    这只是告诉系统当XmlHttpRequest从服务器获取数据时要调用回调函数。如果您有多个具有不同回调的XmlHttpRequests,则需要确保每个回调都注册到正确的XmlHttpRequest。

  4. This is the text processing that is involved in turning the HTML code into a DOM tree. It is often done automatically by the browser, so your javascript should not need to worry too much about it.

    这是将HTML代码转换为DOM树所涉及的文本处理。它通常由浏览器自动完成,因此您的javascript不需要太担心它。

  5. This just means the data processing you are doing with the data you received from the server. It will depend on what data you are getting and what you want to do with it.

    这只是表示您使用从服务器收到的数据进行的数据处理。这取决于您获得的数据以及您想要使用的数据。

#1


1  

The DOM is an object representation of the HTML code. HTML documents are just simple text files, but it is often useful to consider one like it is a tree of elements. So, if your html contains <body><div>hello</div><div>world</div></body> then the DOM will have a "body" object that contains two "div" objects as children. It lets you examine and modify an HTML document in a program without having to do text parsing of the HTML code.

DOM是HTML代码的对象表示。 HTML文档只是简单的文本文件,但考虑它是一个元素树通常很有用。因此,如果您的html包含

hello
world ,那么DOM将有一个“body”对象,其中包含两个“div”对象作为子对象。它允许您在程序中检查和修改HTML文档,而无需对HTML代码进行文本解析。

  1. A DOM event is raised when the user interacts with an element of the DOM, so it's something like an "onclick" or "onkeypress" event. It will have an event handler, which is a function containing code to execute when the event occurs.

    当用户与DOM的元素交互时,会引发DOM事件,因此它类似于“onclick”或“onkeypress”事件。它将有一个事件处理程序,它是一个包含在事件发生时执行的代码的函数。

  2. Because the XmlHttpRequest is asynchronous. After the request is sent, the page will not wait for the response but instead will continue executing the rest of your code. The callback function waits for the response from the server and then executes. So your code to request data from the server should go in the event handler, and the code to process the data goes in the callback.

    因为XmlHttpRequest是异步的。发送请求后,页面不会等待响应,而是继续执行其余代码。回调函数等待来自服务器的响应然后执行。因此,从服务器请求数据的代码应该放在事件处理程序中,处理数据的代码将在回调中进行。

  3. This just tells the system that the callback function is to be called when the XmlHttpRequest gets data back from the server. If you had multiple XmlHttpRequests with different callbacks you would need to make sure each callback is registered to the right XmlHttpRequest.

    这只是告诉系统当XmlHttpRequest从服务器获取数据时要调用回调函数。如果您有多个具有不同回调的XmlHttpRequests,则需要确保每个回调都注册到正确的XmlHttpRequest。

  4. This is the text processing that is involved in turning the HTML code into a DOM tree. It is often done automatically by the browser, so your javascript should not need to worry too much about it.

    这是将HTML代码转换为DOM树所涉及的文本处理。它通常由浏览器自动完成,因此您的javascript不需要太担心它。

  5. This just means the data processing you are doing with the data you received from the server. It will depend on what data you are getting and what you want to do with it.

    这只是表示您使用从服务器收到的数据进行的数据处理。这取决于您获得的数据以及您想要使用的数据。