www.webdeveloper.com
Results 1 to 5 of 5

Thread: Ajax cross-domain calls

  1. #1
    Join Date
    Feb 2006
    Posts
    13

    Question Ajax cross-domain calls

    I'm trying to write a script that will be loaded from one server into a website on another server. This script is trying to talk (ajax) to the server that it comes from but I'm getting "Access Denied" errors.

    I'm well aware that cross-domain calls are not allowed for security reasons so my question is how does Google Analytics work because essentially thats what I'm trying to accomplish.

    I can embed a Google Analytics script into my website and it'll gather data and send it back to Google. Wondering how they do it?

    Help is much appreciated.

    Nik

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    just don't use XMLHttpRequest, and you'll be fine; javascript can come from any domain.

  3. #3
    Join Date
    Feb 2006
    Posts
    13
    what should I use instead of XMLHttpRequest?

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by vitasnik View Post
    what should I use instead of XMLHttpRequest?
    two options:
    Code:
    function ping(paf){
       var i = new Image();
       i.src=paf;
    }//end ping
    
    
    function addScript(u){
       var sc2=document.createElement('script'); sc2.src=u; 
        return  document.getElementsByTagName('head')[0].appendChild(sc2);
    }

  5. #5
    Join Date
    Feb 2006
    Posts
    13
    Hahaha, brilliant...and so simple.

    Thanks a million!

    Much appreciated.

    Nik

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles