| Код | <B>Короткий пример</B> <u onClick=loadXMLDoc(this,'JsPrimeryCode-40.xml')>XMLHttpRequest</u><br> <script> function loadXMLDoc(t,url){var Q=new Object; Q=(window.XMLHttpRequest?new XMLHttpRequest(): (window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new Object)); Q.onreadystatechange=function(){ // only if req. shows "complete" if (Q.readyState==4){//alert(Q.status+' '+Q.statusText); // only if "OK" if (Q.status==200||location.href.indexOf('http:')<0&&Q.status==0){//t.innerHTML+=Q.responseText; t.innerHTML+=Q.responseXML.documentElement.nodeName; //for(i in Q.responseXML){alert(i+'='+eval('Q.responseXML.'+i));} } }}; Q.open("GET",url+'?'+Math.random(),!0);Q.send(null); }
|
(PHP не нужен) Файл 'JsPrimeryCode-40.xml':| Код | <response value="12345"> <<method value="123456">This is </method> example <result>of Suggest></result> </response>
|
Примечание - если IE, то запускать только через веб-север (localhost/...), c локального файла этот метод не работает, что, конечно, вводит в заблуждение.
Док. - 2 строчки. DOMDocument responseXML
The response to the request is parsed as if it were a text/xml stream. This attributes represents the response as a DOM Document object.
...а потом по-русски здесь: http://zeiss.net.ru/docs/design/dom/index.htm |