javascript ajax

来源:互联网 发布:怎么在淘宝搜岛国片 编辑:程序博客网 时间:2024/06/08 10:14
<!DOCTYPE html><html><head>    <meta charset="UTF-8">    <title>AJAX</title>    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1, user-scalable=no" />    <meta name="apple-mobile-web-app-capable" content="yes">    <meta name="format-detection" content="telephone=no"></head><body></body><script type = "text/javascript" >var xmlHttpRequest = null;function ajaxRequest(url, postParams) {    if (window.ActiveXObject) // IE浏览器    {        xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");    } else if (window.XMLHttpRequest) // 除IE以外的其他浏览器    {        xmlHttpRequest = new XMLHttpRequest();    }    if (null != xmlHttpRequest) {        // 准备向服务器发出一个请求        /*         * GET方式向服务器发出一个请求         * xmlHttpRequest.open("GET", "AjaxServlet?v1=" + v1 + "&v2=" + v2, true);         */        /*         * POST方式向服务器发出一个请求         */        xmlHttpRequest.open("POST", url, true);        // 当发生状态变化时就调用这个回调函数        xmlHttpRequest.onreadystatechange = ajaxCallBack;        // 使用post提交时必须加上下面这行代码        xmlHttpRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");        postParams = typeof(postParams) == "string" ? postParams : JSON.stringify(postParams);        // 向服务器发出一个请求        xmlHttpRequest.send(postParams);    }}function ajaxCallBack() {    console.log("[readyState] " + xmlHttpRequest.readyState);    if (xmlHttpRequest.readyState == 4) {        console.log("[status] " + xmlHttpRequest.status);        if (xmlHttpRequest.status == 200) {            console.log("[responseText] " + xmlHttpRequest.responseText);            // var content = xmlHttpRequest.responseText;            // document.getElementById("div1").innerHTML = content;        }    }}ajaxRequest(    "https://113.78.134.110:21900/api/trade/ptjy/ptyw/zjcx", {        "hbdm": "",        "khbz": "2006001283",        "khbzlx": "Z",        "jymm": "111111",        "sessionid": "0",        "token": "0",        "yybdm": "5010",        "lhxx": "aaaaaaa"    });</script></html>

0 0
原创粉丝点击