Afficher le contenu d'un php par ajax crossdomain

Afficher le contenu d'un php par ajax crossdomain - HTML/CSS - Programmation

Marsh Posté le 12-10-2012 à 16:13:05    

Bonjour,
j'aimerai afficher les données d'un autre site (comme un site affiche de la publicité ou un tag de stats par exemple) via javascript. On pourrait dire en gros une iframe en ajax
 
J'ai trouvé deux exemples qui correspondent preque:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Script Loading</title>
<script type="text/javascript">
<!--
 
 function send() {
  var DSLScript  = document.createElement("script" );
  DSLScript.src  = "http://SITEXTERNE.FR/scriptdsl.js";
  DSLScript.type = "text/javascript";
  document.body.appendChild(DSLScript);
  document.body.removeChild(DSLScript);
 }
 
 function callback(sMessage) {
alert(sMessage);
 }
//-->
</script>
</head>
<body>
<script>send();</script>
</body>
</html>

Dans le fichier http://SITEXTERNE.FR/scriptdsl.js il y a  
callback("Hello world !" );
 
Le pop up apparaît bien mais j'aimerai qu'il n'apparaisse pas sous cette forme mais plutot dans le corps de la page  
j'ai remplacé alert(sMessage); par document.write(sMessage); mais cela ne fonctionne pas !
 
 
Le deuxième exemple:
 
<html>
<head>
<script type="text/javascript">
    function xss_ajax(url) {
        var script_id = null;
        var script = document.createElement('script');
        script.setAttribute('type', 'text/javascript');
        script.setAttribute('src', url);
        script.setAttribute('id', 'script_id');
 
        script_id = document.getElementById('script_id');
        if(script_id){
            document.getElementsByTagName('head')[0].removeChild(script_id);
        }
 
        // Insert <script> into DOM
        document.getElementsByTagName('head')[0].appendChild(script);
    }
 
    function callback(data) {
        var txt = '';
        for(var key in data) {
            txt += key + " = " + data[key];
            txt += "\n";
        }
        alert(txt);
    }
 
    var url = "http://SITEEXTERNE.fr/include.php";
 
</script>
<title>Simple Cross Domain Ajax</title>
</head>
<body>
<h1>Simple Cross Domain Ajax</h1>
<button onclick="xss_ajax(url);">Get Data</button>
 
</body>
</html>

 
Dans ce cas on peut même mettre un fichier php !  
Je regarde actuellement comment manipuler le DOM, mais si quelqu'un pouvait m'aider à faire un include crossdomain en Ajax ce serait top :)
 


---------------
I'm a SQwebmaster : http://sqweb.com
Reply

Marsh Posté le 12-10-2012 à 16:13:05   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed