原生ajax、jsoup

ajax 不能跨域訪問,jsoup能夠跨域訪問。ajax

原生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:session

    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=data.result?"1":"0";
        document.getElementById("error-info").value=data.discripe;
    }
相關文章
相關標籤/搜索