Search code examples
javascriptcross-domaindisqus

script tag hack + how do I communicate after the second level of AJAX


I want to provide an embeddable javascript which will get a script from my server . Which in turn will get some details from the user(the page which which has my embeddable js) and put it back onto my server . How do i go about achieving this .

This is the embeddable js i provide .

  <script>
        (function() {
            read="This is the data which is entered by the user"; 
            var istreet = document.createElement('script'); istreet.type = 'text/javascript'; istreet.async = true;
            istreet.src = 'http://xyz.com/a.php;
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(istreet);
        })();

    </script>

And this is the code on http://xyz.com/a.php

$('<div id="content"></div>').appendTo('body');
$('#content').html('
    Some html to inject to the page\'s dom . 
');
$.get("http://xyz.com/process.php?dataToProcess="+read,function(data){
alert(data);
});

But I see that the $.get("http://xyz.com/process.php?dataToProcess="+read,function(data){ // leads to a cross domain ajax request

I do not want to solve the cross domain ajax problem . I want to be able to communicate between the two parties(the one with the embeddable script and my server) seamlessly .


Solution

  • I used this the cross domain iframe hack to commmunicate between the two different domain . I recommend reading this

    http://softwareas.com/cross-domain-communication-with-iframes