zoukankan      html  css  js  c++  java
  • Ajax常用写法

    Just make a note!

    var xmlHttpReq;
    function createXmlHttpRequest() {
        //创建XMLHttpRequest对象
        if(window.XMLHttpRequest) {
            xmlHttpReq = new XMLHttpRequest();
            if(xmlHttpReq.overrideMimeType) {
                xmlHttpReq.overrideMimeType('text/xml');
            }
        } else if(window.ActiveXObject) {
            try {
                xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                }
            }
        }
        if(!xmlHttpReq) {
            alert('Can not create XMLHTTP instance!');
            return false;
        }
    }
    
    //入口,调用Ajax请求
    function callAjax() {
        createXmlHttpRequest();
        var url = "xxxxx";
    
        var query = "methodName=run?a=2";//传递请求的参数
        xmlHttpReq.open("POST", url, true);
        xmlHttpReq.onreadystatechange = callBack;//指定回调函数
        xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttpReq.send(query);//发送请求的参数
    }
    
    //回调函数
    function callBack() {
        if(xmlHttpReq.readyState == 4) {
            if(xmlHttpReq.status == 200) {
                var returnStr = xmlHttp.responseXML; // xmlHttp.responseXML 即为执行后台操作后,返回的值
                    // do what you want with responseXML
            }
        }
    }
  • 相关阅读:
    计算机基础知识-计算机网络知识
    计算机基础知识-操作系统
    计算机基础知识-硬件
    Django REST
    船舶管子零件图程序开发
    OpenCASCADE 参数曲面面积
    Jenkins in OpenCASCADE
    OpenCASCADE BRepMesh
    管道设计CAD系统中重量重心计算
    IsoAlgo3d
  • 原文地址:https://www.cnblogs.com/yejg1212/p/3104036.html
Copyright © 2011-2022 走看看