1, remove both ends blank
function return str.replace (/(^\s*) | ( \s*$)/g, "");}
Implementing Ajax
Ajax:
Asynchronous: Asynchronous
Javascript
And: And
Xml
Ajax technology is the ability to use JavaScript and XML to implement asynchronous interactions
Ajax has its own engine, and the traditional interaction is that the client interacts directly with the sever,
Ajax is the client sends the request to the Ajax engine, and the Ajax engine sends the request to the server,
This implements the asynchronous request
1. Creating an Ajax Object
function createxhr () { try{returnnew XMLHttpRequest ()}catch(e) {} //W3C, also supported in IE High version Try {returnnew activexobject (' Microsoft.XMLHTTP ')} Catch (e) {} //ie alert (' Please change browser ');}
2. Initializing Ajax objects
Xhr.open (' Get ', ' demo01.php ');//open (Mehod,url)
You can also set the request header information here
setRequestHeader (Header,value)///can use 1 (' if-modified-since ', ' 0 ') to eliminate the cache, or you can use the plus random number 2 math.random ()
or random time 3 var url= ' demo01.php?name=huohaifeng&_= ' + new Date (). GetTime ();
or 4 Set the header ("Cache-control:no-cache") on the server side;
3. Send Request
Send (content) only sends the request when the Send method is called, content:post the data that is passed when the request is requested, and if the GET request writes NULL directly
4. Execute callback function
Onreadystatechange=funtion () {} triggers when the Ajax object status code changes
Some other Ajax properties:
Readystate:ajax Object Status Code: 0-4
0: Indicates that the object is established but not initialized
1: Indicates that the object has been initialized but not sent
2: The Send method has been called for request
3: Receiving data
4: Receive complete
Status
The HTTP response status code received by the Ajax object, such as: 200 302 304 404
StatusText
The HTTP response status text received by the Ajax object such as: OK, not found
Reponsetext
The Ajax object receives the HTTP response body string (text/html)
Responsexml
HTTP response body content received by the Ajax object (Text/xml)
Implementing AJAX asynchronous requests