首页 > 代码库 > 原生ajax、jsoup

原生ajax、jsoup

ajax 不能跨域访问,jsoup可以跨域访问。

原生ajax:

    function CreateXmlHttp() {        var xhrobj = false;        try {            xhrobj = new ActiveXObject("Msxml2.XMLHTTP"); //ie msxml3.0+        }        catch (e) {            try {                xhrobj = new ActiveXObject("Microsoft.XMLHTTP"); //ie msxml 2.6            } catch (e2) {                xhrobj = false;            }        }        if (!xhrobj && typeof XMLHttpRequest != ‘undefined‘) { //firefox opera 8.0 safari            xhrobj = new XMLHttpRequest();        }        return xhrobj;    }        var xhr = CreateXmlHttp();    function ajaxGet() {        var url = "http://www.baidu.com?param1=123&param2=jack"        xhr.open("GET", url, false);  //false:同步;true:异步        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");        xhr.setRequestHeader("If-Modified-Since", "0");        xhr.onreadystatechange = callbackHandler;  //回调函数        xhr.send(null); //GET方式    }        window.onload = function(){        ajaxGet();    }

 

jsoup:

    function doEndConference(userid,sessionId){        var url = "http://www.baidu.com?appid=223&callback=callbackHandler";        var script = document.createElement(‘script‘);        script.setAttribute(‘src‘, url);        document.getElementsByTagName(‘head‘)[0].appendChild(script);     };    //回调    function callbackHandler(data){        document.getElementById("get-captcha-result").value=http://www.mamicode.com/data.result?"1":"0";        document.getElementById("error-info").value=http://www.mamicode.com/data.discripe;    }

 

原生ajax、jsoup