标签:src 字符串 会话 解析 flag eth UNC mac size
<html> <head> <script type="text/javascript"> function loadXMLDoc(URL) { // 使用Ajax获取内容之后,在原始页面进行更新 if (window.XMLHttpRequest) { /* code for IE7+, Firefox, Chrome, Opera, Safari */ xmlhttp=new XMLHttpRequest(); // 1.生成XMLHttpRequest对象 } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; /* responseText属性返回字符串形式的响应*/ } } /* 2.将请求发送到服务器。使用 XMLHttpRequest 对象的 open() 和 send() 方法。 */ xmlhttp.open("GET",URL,true); /* open(method,url,async) */ xmlhttp.send(); } function loadXML(URL) { // 使用原生的JS来获一个文件内容 document.location = URL; } </script> </head> <body> <div id="myDiv"><h3>Let AJAX change this text</h3></div> <button type="button" onclick="loadXML(‘test.txt‘)">Change Content with raw JS</button> <!--使用原生的JS来获一个文件内容--> <br> <button type="button" onclick="loadXMLDoc(‘test.txt‘)">Change Content with Ajax</button> <!--使用Ajax获取内容之后,在原始页面进行更新--> </body>
req = new XMLHttpRequest();
req = new ActiveXObject("Microsoft.XMLHTTP"); req = new ActiveXObject("Msxml2.XMLHTTP");
方法 | 描述 |
open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) | 设置目的 URL 、方法、同 / 异步以及其他可选参数 |
getAllResponseHeaders() | 获得返回头部中的所有信息 |
getResponseHeader("headerLabel") | 获得返回头部信息中的特定内容 |
send(content) | 发送该请求(携带参数) |
setRequestHeader("label", "value") | 设置请求头部中的值 |
<html> <head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","1.txt",true); // xmlhttp.open(“POST","1.txt",true); xmlhttp.send(); } </script> </head> <body> <div id="myDiv"><h2>Let AJAX change this text</h2></div> <button type="button" onclick="loadXMLDoc()">Change Content with Ajax</button> </body> <html>
xmlhttp.open("GET","1.txt",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("fname=Bill&lname=Gates");
setRequestHeader("Content-type","application/x-www-form-urlencoded");
属性 | 描述 |
onreadystatechange | 连接会话的每次状态变化都会触发该属性 状态:打开请求、准备发送、发送成功、返回 |
readyState | 连接的状态( 0~4 ) 状态4:收到回复 |
responseText | 服务器返回的应答内容 |
status | 服务器返回的页面状态,如 404 “Not Found” 或者是 200 "OK" |
statusText | 描述状态的文字 |
if (xhr.readyState == 4) { alert(xhr.readyState+"\n Loaded, Ready to display!"); if(xhr.status==200) { alert("really ready!"); document.getElementById("symbol").innerHTML = xhr.responseText; } } else if (xhr.readyState == 3) alert(xhr.readyState+"\n receiving..."); else if (xhr.readyState == 2) alert(xhr.readyState+"\n sent request!"); else if (xhr.readyState == 1) alert(xhr.readyState+"\n open() opened!"); else if (xhr.readyState == 0) alert(xhr.readyState+"\n Uninitialized!");
function handler() { // only handle loaded requests if (xhr.readyState == 4) { if (xhr.status == 200) { alert(xhr.status + "\nPage Ready!"); document.getElementById(‘symbol‘).innerHTML = xhr.responseText; } else if (xhr.status == 404) alert(xhr.status+"\nPage not found!"); else if (xhr.status == 403) alert(xhr.status+"\nAccess Denied!"); } }
if (xhr.status == 200) { alert(xhr.status + "\nPage Ready!"); document.getElementById(‘symbol‘).innerHTML = xhr.resp onseText; } else if (xhr.status == 404) alert(xhr.status+"\nPage not found!"); else if (xhr.status == 403) alert(xhr.status+"\nAccess Denied!");
<img src="w3.gif" onload="loadXMLDoc();alert(1);" /> <img src="w3.gif" />
xmlhttp.open("POST","1.php",false); //loadXMLDoc()加载的文件 Sleep(10); //返回文件之前等待10s
<!-- A basic example to demonstrate asynchronous. --> <html> <head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } // xmlhttp.open("GET","1.php",true); // xmlhttp.open("GET","1.php",false); // xmlhttp.open("POST","1.php",false); xmlhttp.open("POST","1.php",true); xmlhttp.send(); } </script> </head> <body > <div id="myDiv"><h2>Let AJAX change this text</h2></div> <img src="w3.gif" onload="loadXMLDoc();alert(1);" /> </body> </html>
<!--1.php--> <?php sleep(10); ?> <html> <head> <title></title> </head> <body> <form action="" method="get" > Symbol: <textarea id="symbol" name="symbol" type="text"> </textarea> <br><br> <input type="submit" value="Get Quote"> </form> <script> document.getElementById(‘symbol‘).innerHTML="<?php print("hello");?>"; </script> </body> </html>
xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","test1.txt",true); xmlhttp.send();
xmlhttp.open("GET","test1.txt",false); xmlhttp.send(); document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
标签:src 字符串 会话 解析 flag eth UNC mac size
原文地址:https://www.cnblogs.com/tianjiazhen/p/12235894.html