我的一些关于“ AJAX”的疑问!

我在Ajax上工作了几个月,Ajax请求如下:

  1. 1、将参数传递到后台页(PHP/ASP/HTML/TXT/XML)

  2. 2、在服务器上做一些处理

  3. 3、返回结果并显示给客户端(HTML/XML/JSON)

但是,如果我想在请求生命周期中添加其他内容,这个过程显然是不能满足的,现在有一些关于Ajax的问题,我将尝试一个一个地对它们进行描述。

  1. 1、可以发出多少并发Ajax请求?

  2. 2、是的,Ajax中有超时时间,但是考虑到Web2.0场景和网络的可能性,超时时间是什么?最佳实践?

  3. 3、考虑一下这样的场景:如果用户调用Ajax请求,并且它正在服务器上进行,同时用户离开了页面。服务器上的处理是否会以中断的方式进行?或者服务器上的所有执行都将完成并将响应发送回浏览器?会发生什么?

  4. 4、我们是否严格要求有一个服务器页面(PHP/JSP/ASP)来接受Ajax请求?考虑到Ajax的广泛使用,在服务器上,我们需要实现每个请求的页面(或多个请求之间的几个页面),这是很难维护的。

  5. 5、我们可以有其他的东西代替服务器端页面(PHP/ASP等)吗?比如Web服务或者可以直接从Ajax(JavaScript)请求的东西,比如URL?如果是,怎么做?这可以减少对额外服务器端页面的需求。

  6. 6、Ajax请求还支持身份验证。在什么情况下使用这个?是强制性的吗?

  7. 7、Comet是我经常听到的东西,我对它的理解是,它只是使用Ajax通过轮询机制获取更新数据的某种模式。这是对的吗?请提供您的意见/见解。

  8. 8、使用Ajax有安全风险吗?如何才能减轻(加密/解密)?

谢谢大家!

  1. Depends on the browser. It follows the same rules as concurrent HTTP requests everywhere else in the browser.

  2. Ditto.

  3. Pretty much the same as the user hitting the Stop button on a regular page.

  4. An HTTP request must request a URI. How you handle that on the backend is up to you. The term "page" doesn't really fit — that is an HTML document with associated resources (stylesheets, images, etc). Most systems don't have a 1:1 mapping between server side programs and resources. In an MVC pattern, for example, it isn't uncommon to have a shared model and a controller that just switches between views for determining if to return an HTML document or the same data expressed in JSON.

  5. A web service is just a server side program that responds in a particular way, lots of people write them using PHP, JSP or ASP so the question doesn't really make sense.

  6. No, it isn't mandatory. You use authentication when you need authentication. There is no special "ajax authentication", that is usually just using the same cookies that are used everywhere else in the site.

  7. No, the point of Comet is to avoid polling. See http://en.wikipedia.org/wiki/Comet_%28programming%29

  8. Requests containing data are sent to the server. Responses containing data are returned from the server. The security implications are no different to any other HTTP request you handle.

You must use the URI to use it