标签:jaxp style code app chrome 请求 异步 logs ie7
Ajax API
var reqUrl = "http://192.168.31.162:8081/obtain/onlineState?name=aa01&password=010203"; var postUrl = "http://192.168.31.162:8081/update/remoteClientInfo"; /** * 页面 * http://192.168.31.162:8081/http/ajax/Aj01-HttpRequest.html * ajax get 请求 * http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_send.asp */ function testAjaxGet() { debugger; var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET", reqUrl, true); // xmlhttp.open("GET", reqUrl, false); xmlhttp.send(); // console.log(xmlhttp.responseText); xmlhttp.onreadystatechange = function () { // 异步方法回调 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { console.log(xmlhttp.responseText); } } } /** * Ref: * */ function testAjaxPost() { debugger; var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("POST", postUrl, true); // xmlhttp.open("POST", postUrl, false); xmlhttp.setRequestHeader("Content-type","application/json"); var jsonObj = { name:"AAA" }; xmlhttp.send(JSON.stringify(jsonObj)); // console.log(xmlhttp.responseText); xmlhttp.onreadystatechange = function () { // 异步方法回调 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { console.log(xmlhttp.responseText); } } }
参考:
AJAX - 向服务器发送请求 w3c
标签:jaxp style code app chrome 请求 异步 logs ie7
原文地址:http://www.cnblogs.com/zhen-android/p/7643382.html