Tu peut essayer avec:
<input type="text" id="entreprise" onblur="fonction()">
Dans le fichier javascript
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
|
function fonction()
{
var xhr=createXHR();
var rst;
xhr.open("POST", 'fichier.php',true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)
{
rst=xhr.responseXML;
{
document.getElementById('addresse').value= rst.getElementsByTagName('addresse')[0].childNodes[0].nodeValue;
document.getElementById('telephone').value= rst.getElementsByTagName('telephone')[0].childNodes[0].nodeValue;
document.getElementById('fax').value= rst.getElementsByTagName('fax')[0].childNodes[0].nodeValue;
document.getElementById('mail').value= rst.getElementsByTagName('mail')[0].childNodes[0].nodeValue;
}
}
else
{
alert("Error: returned status code " + xhr.status + " " + xhr.statusText);
}
}
}
var entreprise='entreprise='+document.getElementById('entreprise').value;
xhr.send(entreprise);
} |
Et en fin le fichier.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?php
if(isset($_POST['entreprise']))
{
mysql_connect("localhost","root","root");
mysql_select_db("test");
$res = mysql_query("SELECT addresse,telephone,fax,mail FROM dansTable WHERE entreprise=".$_POST["entreprise"]);
$row = mysql_fetch_assoc($res))
header("Content-type:text/xml");
echo'<?xml version="1.0" encoding="ISO-8859-1"?><entreprise>';
{
echo "<addresse>".$row['addresse']."</addresse>";
echo "<telephone>".$row['telephone']."</telephone>";
echo "<fax>".$row['fax']."</fax>";
echo "<mail>".$row['mail']."</mail>";
}
echo'</enterprise>';
}
?> |
Partager