Home > front end >  JavaScript asynchronous ajax summary
JavaScript asynchronous ajax summary

Time:09-20

JavaScript asynchronous ajax summary
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Development tools and key technology: Visual Studio 2015 and JavaScript
Author: wen-jian tang
Writing time: on April 30, 2020,
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Ajax is what?
Is not a programming language, that is able to part don't have to reload the whole page updated technology,
Synchronous and asynchronous:
Synchronous: for example after three people go to the supermarket to buy things to pay but there is only one supermarket checkout that they shall be lined up this time
Asynchronous: supermarket checkout has three they can pay at the same time, it lost a lot of time,
Asynchronous implementation:
1, using HTML and CSS pages, express information
2, using the XMLHttpRequest and web server for the exchange of asynchronous data
3, use JavaScript DOM operation, realize the dynamic local refresh
Then create the:
Var XHR=null;
If (window. The XMLHttpRequest) {
XHR=new XMLHttpRequest ();
} else {
XHR=new ActiveXObject (" Microsoft. XMLHTTP ");
}
The form of asynchronous process:
Write a function
Var XHR=null; If (window. The XMLHTTPRequest) {
Xhr=new XMLHTTPRequest ();
} else {
XHR=new ActiveXObject (" Microsoft. XMLHTTP "); }
This is used to solve the problem of browser compatibility and wrote a variable
XHR. Open (method and path)
XHR. Send (send)
A relatively fixed grammar server response at present:
XHR. Onreadystatechange=function () {
If (XHR. ReadyState==4 & amp; & XHR. Status==200) {
The console. The log (XHR. The responseText);
In this statement declaring variables=JSON. Parse (fill in to print data)
Access to elements and show them to the value of the variable declaration. Elements of the document. The getElementById (" txtName "). value=https://bbs.csdn.net/topics/obj.name;

Data submitted to the server page
Write a function, gain element and displayed. The value
Create a XMLHTTP object and written code browser compatibility problems
Sends a request to the server XMLHTTP. Open (method, path)
Specify the response headers: XMLHTTP. SetRequestHeader (" the content-type ", "application/x - WWW - form - urlencoded");
Var STR="name=" + name + "& amp; Sex="+ +" sex & amp; Address="+ address; Be spliced element
To send data XMLHTTP. Send (STR);
The server response a fixed statement
Access to the server returns the results of the

Josn:

JS object into a JSON object:
Stringify (string);
The Parse (analysis);
Stringify () : the JS object serialization for JSON string
Column: var STR=JSON. Stringify (obj);
The Parse () [pa: z] : converting the JSON string to JS value
Column: a JSON variable
Avr obj1=JSON. Parse (parameters)

  • Related