1,
Ajax: Asynchronous JavaScript and XML (first review Ajax)
VaRXMLHttpRequest;
FunctionAjaxtest ()
{
If(Window. activexobject)
XMLHttpRequest =NewActivexobject ("Microsoft. XMLHTTP ");
// XMLHttpRequest = newactivexobject ("msxml2.xmlhttp"); // suitable for new ie versions, but the above can also be used
Elseif(Window. XMLHttpRequest)
XMLHttpRequest =NewXMLHttpRequest ();
If(XMLHttpRequest! = "Undefined ")
// If ("undefined "! = XMLHttpRequest) // do not recommend this method. It may be incorrect in IE.
{
// Prepare data, GET request; url = ajaxservlet; true indicates asynchronous Processing
VaRUrl = "$ {pagecontext. Request. contextpath}/ajaxservlet ";
// Submit the request in get mode, with parameters following the URL
/* XMLHttpRequest. Open ("get", URL, true );
XMLHttpRequest. onreadystatechange = ajaxcallback; // callback function
XMLHttpRequest. Send (null); // send the request
*/
// Submit in post Mode
XMLHttpRequest. Open ("Post", URL,True);
XMLHttpRequest. onreadystatechange = ajaxcallback ;//
Callback Function
VaRJSON = {"001": "A", "002": "B "};
XMLHttpRequest. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded"); // you must add
XMLHttpRequest. Send ("JSON =" + JSON. stringify (JSON ));
// Send the request
}
}
FunctionAjaxcallback ()
{
If(XMLHttpRequest. readystate = 4)
{
If(XMLHttpRequest. Status = 200)
{
VaRJSON = eval ('+ XMLHttpRequest. responsetext + ')');
For(VaRIIn
JSON)
{
Alert (I +
"," + JSON [I]);
}
}
}
}
2. www.jquery.com: write less, do more
<Scripttype ="Text/JavaScript"Src =Jquery-1.7.2.js"> </SCRIPT>
<Scripttype ="Text/JavaScript">
// After the DOM file is loaded, it will be executed in sequence. The onload event is an object reference. After the page is loaded and the related preparations such as the association number Dom are completed, the task will be executed, and only the last reference will be executed.
$ (Document). Ready (Function()
{
Alert ("hello ");
});
$ (Document). Ready (Function()
{
Alert ("world ");
});
</SCRIPT>
The HTML elements obtained by jquery are in the form of arrays.
VaR d = Document. getelementbyid ("div1 ");
Alert (D. innerhtml );
// The function of converting Dom to jquery object is extended
VaR JD = $ (d );
Alert(jd.html ());
// Jquery object --> convert to DOM object
VaR E = $ ("A") [0];
Alert (E. innerhtml );
3. jquery Selector
////////// First check the CSS selector.
A. Tag selector, which uses the Tag Name of the document element as the selector
B. ID selector, id value of an element attribute in the document
C. The class selector Div. x applies to the class = "X" element in the DIV element, and. X indicates to reference all document elements whose class = "X" is referenced in the document.
D. Group selector TD, TB, Div. {...}
E. Descendant selector # links
F. wildcard selector * indicates all content
/////////// Jquery Selector