开发者

want to create a js plugin that sends a lot of data async to another server

is there a way i can send a lot of data to another server asynchronously via javascript without running into cross domain problems?

how is google开发者_JS百科 analytics able to send their encoded data to their servers?


you can use Ajax to send a lot of data.

Native Javascript:

function NewAjax(){
var xmlhttp=false;
try{
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
    try{
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(E){
        xmlhttp = false;
    }
}

if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
    xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
} 
function load_page (url, container){
ajax=NewAjax(); 
ajax.open("GET", url,true); 
ajax.onreadystatechange=function(){
    if(ajax.readyState==1){
        container.innerHTML = "loading";//<-- Preload
    }else if(ajax.readyState==4){
        //Page loaded
        if(ajax.status==200){
            //OK
            container.innerHTML = ajax.responseText;
            add_action();

        }else if(ajax.status==404){
            //Page doesn't exist
            container.innerHTML = "Erro loading page";
        }else{
            //Show error 
            container.innerHTML = "Error:".ajax.status; 
        }
    }
}
ajax.send(null); }

Or

JQuery Ajax:

$.ajax({url: 'ajax/test.html',
success: function(data) {
$('.result').html(data);
alert('Load was performed.');}});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜