简体   繁体   English

xmlhttprequest在请求处理后是否保持连接打开?

[英]Does xmlhttprequest keep connection open after request has been processed?

I have done a simple ajax... 我做了一个简单的ajax ......

The request and response header both contain the Connection: Keep-Alive 请求和响应标头都包含Connection: Keep-Alive

I goggle a bit and saw that the client thus maintain a persistent connection with the server. 我凝视了一下,发现客户端因此与服务器保持持久连接。 This support pipelining, where client may send multiple request without waiting for each response. 这支持流水线操作,客户端可以在不等待每个响应的情况下发送多个请求。

So i have some questions: 所以我有一些问题:

  1. Where does the xmlhttprequest actually open a connection to the server? xmlhttprequest实际上在哪里打开与服务器的连接?
  2. Does creating many xmlhttprequest object open their own connect or it send it on a same connection using pipelining...? 创建许多xmlhttprequest对象是打开它们自己的连接还是使用流水线将它发送到同一个连接上?
  3. I want to handle simultaneous request.. Can i queue the request(store parameters) ..and in the onreadystate provide function to handle it.. ie calling the function that make request recursively? 我想处理同时请求..我可以排队请求(存储参数)..并在onreadystate提供函数来处理它..即调用递归请求的函数? or it's not a good idea at all? 或者它根本不是一个好主意?
  4. When is the connection closed..at what stage? 连接什么时候关闭..在什么阶段?

Other info: I don't want to use jquery or any other librarie for the ajax.You can propose though. 其他信息:我不想使用jquery或任何其他图书馆的ajax.You可以提出。 i can check how they work. 我可以检查它们是如何工作的。 I'm using javascrip and php(codeigniter framework). 我正在使用javascrip和php(codeigniter框架)。 I want to be able to handle multiple request(2)..and queue request that are made when the limit has been reached. 我希望能够处理多个请求(2)..和队列请求,达到限制时。

Thanks in advance :) 提前致谢 :)

XMLHttpRequest is an object which let you to request and receive data from server without refreshing the page. XMLHttpRequest是一个对象,它允许您在不刷新页面的情况下从服务器请求和接收数据。 It uses HTTP or HTTPS requests. 它使用HTTPHTTPS请求。 It is basically same as requesting and receiving an HTML page. 它与请求和接收HTML页面基本相同。 You may open them synchronous or asynchronous. 您可以同步或异步打开它们。

XMLHttpRequest.open( Method, URL, Asynchronous, UserName, Password )

Here, Method is HTTP request method to use. 这里, Method是要使用的HTTP请求方法。 See http://www.w3.org/TR/XMLHttpRequest/#the-open()-method http://www.w3.org/TR/XMLHttpRequest/#the-open()-method

I want to handle simultaneous request.. Can i queue the request(store parameters) ..and in the onreadystate provide function to handle it.. ie calling the function that make request recursively? 我想处理同时请求..我可以排队请求(存储参数)..并在onreadystate提供函数来处理它..即调用递归请求的函数? or it's not a good idea at all? 或者它根本不是一个好主意?

I'd make an array of XMLHttpRequests and handle data and remove XMLHttpRequest from array onreadystatechange . 我将创建一个XMLHttpRequests数组并处理数据并从数组onreadystatechange删除XMLHttpRequest。 Keep in mind that you will receive a mixed order of asynchronous responses or may not receive a response at all. 请记住,您将收到异步响应的混合顺序,或者根本不会收到响应。

When is the connection closed..at what stage? 连接什么时候关闭..在什么阶段?

It is closed right after data is received. 它在收到数据后立即关闭。 Note that keep-alive is about keeping the session alive, not the connection. 请注意, keep-alive是关于保持会话活动,而不是连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM