The seventh chapter:
The 1.dom method creates and inserts tags: (this method does not change the physical contents of the document, but rather changes the DOM tree)
① creating ELEMENT nodes: createelement ();
② internal Front Insert: appendchild ()
③ Creating a text node: createTextNode ();
④ set Attribute node: SetAttribute ();
⑤ Outer front Insert: parent element. insertbefore (inserted element, target element); The inserted element is inserted in front of the target element.
⑥ has no inserafter () function.
2. Small Knowledge point : ①Appendchid (this element cannot be quoted, otherwise it is a string)
②Ajax Onreadysatechange () This function is lowercase . Do not know why do not follow the camel's writing, when the first write, generally will write wrong.
③ at Aja Post, the request header, the header, where Content-type is set to application/x-www-form-urlencoded, is sent in the form of a simple key-value.
It can also be set to Form-data, which is typically used to transfer files. (compared to tablets, etc.). Transferring pictures to the server at work is to convert the picture into a binary stream, then post to send, while Content-type is set to Form-data
3.ajax process, Code:
1 varXMLHTTP;2 //stationary degradation-object detection technology3 //1. Create an Object4 if(window. XMLHttpRequest) {5XMLHTTP =NewXMLHttpRequest ();//for ie7+, FireFox, Chrome, Safari, Opera6}Else{7XMLHTTP =NewActivexobjext ("Microsoft.XMLHTTP");//suitable for IE5, IE68 }9 //2. Determine the request type, send the requestTenXmlhttp.open ("GET", "ajax1.php",true); One xmlhttp.send (); A - //Xmlhttp.open ("POST", "t1.html", true); - //Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); the //xmlhttp.send ("a=1&b=2"); - - //3. Response Request (ReadyState 0-Request uninitialized; 1-link to server; 2-Request accepted; 3-Request processing; 4-request processing completed) -Xmlhttp.onreadystatechange =function(){ + if(Xmlhttp.readystate = = "4" && xmlhttp.status = = "200"){ - varp = document.createelement ("P"); + varPtext =document.createTextNode (xmlhttp.responsetext); A p.appendchild (Ptext) at varBODY = document.getElementsByTagName ("body") [0]; - Body.appendchild (p); - } - } - - //say at the end: browsers generally prohibit Ajax from using the FILE://protocol. Indicates that cross-domain requests only support protocols such as HTTP. So when testing the implementation, install a software similar to Phpstudy. Make your machine into a virtual server.
JavaScript DOM Programming Art-Learning notes (seventh)