[AJAX] Ajax n'ouvre pas une page php
bonjour, je veux faire un POST avec ajax, la transmission se déroule parafaitement mais le problème c'est qu'il n'ouvre pas la page de destination (reponse.php)
code js:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| var x = 4;
convertion(x);
function convertion(x){
var xhr;
try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e)
{
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2)
{
try { xhr = new XMLHttpRequest(); }
catch (e3) { xhr = false; }
}
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4 && xhr.status == 200)
{}}
xhr.open("POST","reponse.php",true);
xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
xhr.send("varx="+x);
} |
code reponse.php
Code:
1 2 3 4 5 6 7 8
| <?php
echo "<h1>réponse</h1>";
if (isset($_POST["varx"])){
$varx_recup=$_POST["varx"];
echo 'variable x =';
echo $varx_recup;
}
?> |