Bonsoir a tous,

J'ai un souci, je ne parviens pas à récuperer la réponse du fichier distant (autre serveur et autre hebergeur) dans le <tr> de ma page.

Faut il que je spécifie aussi un id pour le tbody ?

Merci de votre précieuse aide.

Bonne soirée




Mon script de base :

Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<style>
        td {text-align:center;}
        th {text-align:center; font-weight:bold}
</style>
 
<script type="text/javascript">
    function fct_toto() 
    {
        
        var xhr_object = new XMLHttpRequest();
        xhr_object.open("GET", "https://www.domain_externe.com/fichier.php", true);
        xhr_object.onreadystatechange = function() {if(xhr_object.readyState == 4) 
            {
                document.getElementById("nomdematable").rows["nomdemontr"].innerHTML = xhr_object.responseText ;
            }
        }
        xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr_object.send(null);
    }
 
</script>
</head>
 
<body onload="fct_toto();">
<?php
 
echo '
<table id="nomdematable" width="100%" border="1">
        <thead>
        <tr>
            <th>AAAAA</th>
            <th>BBBBB</th>
        </tr>   
    </thead>
    <tbody>
          <tr id="autrenomdetr" name="autrenomdetr"></tr>
    </tbody>
    <tbody>
          <tr id="nomdemontr" name="nomdemontr"></tr>
    </tbody>
</table>';
?>

Le fichier distant hebergé sur le serveur distant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
<?php
header("Access-Control-Allow-Origin: *");
echo '<td>1111111</td><td>2222222</td>';
?>