8
1
2008
2

[Ajax]Ajax readyState的几种状态

0: (Uninitialized) the send( ) method has not yet been invoked.
1: (Loading) the send( ) method has been invoked, request in progress.
2: (Loaded) the send( ) method has completed, entire response received.
3: (Interactive) the response is being parsed.
4: (Completed) the response has been parsed, is ready for harvesting.

0 - (未初始化)还没有调用send()方法
1 - (载入)已调用send()方法,正在发送请求
2 - (载入完成)send()方法执行完成,已经接收到全部响应内容
3 - (交互)正在解析响应内容
4 - (完成)响应内容解析完成,可以在客户端调用了

 

readyState Status Code

Status of the XMLHttpRequest Object

(0) UNINITIALIZED
未初始化

The object has been created but not initialized. (The open method has not been called.)
(XMLHttpRequest)对象已经创建,但尚未初始化(还没有调用open方法)。

(1) LOADING
载入

The object has been created, but the send method has not been called.
(XMLHttpRequest)对象已经创建,但尚未调用send方法。

(2) LOADED
载入完成

The send method has been called, but the status and headers are not yet available.
已经调用send方法,(HTTP响应)状态及头部还不可用。

(3) INTERACTIVE
交互

Some data has been received. Calling the responseBody and responseText properties at this state to obtain partial results will return an error, because status and response headers are not fully available.
已经接收部分数据。但若在此时调用responseBody和responseText属性获取部分结果将会产生错误,因为状态和响应头部还不完全可用。

(4) COMPLETED
完成

All the data has been received, and the complete data is available in the responseBody and responseText properties.
已经接收到了全部数据,并且在responseBody和responseText属性中可以提取到完整的数据。

 

比如在点完保存以后显示正在保存的状态时应该判断readyState == 2的时候,执行显示的状态

Category: JavaScript | Tags: php ajax
8
1
2008
1

[PHP]Ajax使用POST传值要注意的一个小问题

昨天在一个保存按钮的地方用到了Ajax

使用POST传值,在提交的时候执行页面怎么也接受不到传的值,用get却没有问题

最后发现问题出在setRequestHeader('Content-Type','utf-8');

必须设置成setRequestHeader('Content-Type','application/x-www-form-urlencoded');

这样才能接受到post的值

Category: PHP | Tags: ajax php

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com