0

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 analytics able to send their encoded data to their servers?

john
  • 33,520
  • 12
  • 45
  • 62
  • [How does Google's javascript API get around the cross-domain security in AJAX](http://stackoverflow.com/questions/129053/how-does-googles-javascript-api-get-around-the-cross-domain-security-in-ajax) – YOU Apr 11 '11 at 04:26

1 Answers1

0

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.');}});