Created
August 20, 2018 15:42
-
-
Save liuliqiang/ac6c0fff334d408b91f3da28082863cc to your computer and use it in GitHub Desktop.
XMLHTTPRequest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<!-- created by https://liqiang.io --> | |
<head> | |
<script type="text/javascript">function loadXMLDoc() { | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
document.getElementById("myDiv").innerHTML = xmlhttp.responseText; | |
} | |
} | |
xmlhttp.open("POST", "/ajax/demo_post2.asp", true); | |
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
var body = { | |
fname: "Bill", | |
lname: "Gates" | |
} | |
xmlhttp.send(JSON.stringify(body)); | |
}</script> | |
</head> | |
<body> | |
<h2>AJAX</h2> | |
<button type="button" onclick="loadXMLDoc()">请求数据</button> | |
<div id="myDiv"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<!-- created by https://liqiang.io --> | |
<head> | |
<script type="text/javascript">(function() { | |
var json = '{"result":true, "count":42}'; | |
obj = JSON.parse(json); | |
console.log(obj.count); | |
// expected output: 42 | |
console.log(obj.result); | |
// expected output: true | |
})()</script> | |
</head> | |
<body></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<!-- created by https://liqiang.io --> | |
<head> | |
<script type="text/javascript">function loadXMLDoc() { | |
// code for IE7+, Firefox, Chrome, Opera, Safari | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
console.log(xmlhttp.responseText); | |
} | |
} | |
xmlhttp.open("GET", "/ajax/demo_get.asp", true); | |
xmlhttp.send(); | |
}</script> | |
</head> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment