HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
When a request is sent to the server, based on the response we need to perform some tasks.
Whenever readyState changes will trigger onreadystatechange event.
there XMLHttpRequest readyState property status information.
Here is the XMLHttpRequest object three important properties:
属性 | 描述 |
---|---|
onreadystatechange | 存储函数(或函数名),每当 readyState 属性改变时,就会调用该函数。 |
readyState | 存有 XMLHttpRequest 的状态。从 0 到 4 发生变化。
|
status | 200: "OK" 404: 未找到页面 |
In the onreadystatechange event, we require that the server responds when the task is ready to be processed when executed.
When the readyState and status equal to 4 to 200, a response ready:
Note: onreadystatechange event is triggered 5 times (0--4), corresponding to each of the readyState changes.
Is a callback function passed as a parameter to another function.
If multiple AJAX tasks exist on your site, then you should create XMLHttpRequest object to write a standard function, and the function is called for each AJAX task.
URL should contain the function call and the tasks performed onreadystatechange event occurs (for each call may vary):