日期:2014-05-16  浏览次数:20603 次

最简单的实现ajax提交和获取

 

function AjaxGetXml(serviceUrl, soapAction, data) {
    var xmlHttp;
    try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
        try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) {
            try { xmlHttp = new XMLHttpRequest(); }
            catch (e) { return null; }
        }
    }
    try {
        var url = serviceUrl + "/" + soapAction;
        xmlHttp.open("POST", url, false);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.send(data);
        if (xmlHttp.status != 200) {
            return null;
        }
        try //Internet Explorer 
        {
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(xmlHttp.responseText);
            return xmlDoc;
        } catch (e) {
            try //Firefox, Mozilla, Opera, etc. 
            {
                parser = new DOMParser();
                return parser.parseFromString(xmlHttp.responseText, "text/xml");
            } catch (e) {
                return null;
            }
        }
    }
    catch (e) {
        return null;
    }
}

欢迎访问:http://121.18.78.216适易查询分析、工作流、内容管理及项目管理演示平台