[AJAX] eval et javascript
Bonjour,
Je suis sensé reprendre une page que quelqu'un à codé avec Ajax. Malgré ma méconnaissance du sujet j'ai réussi à corriger tout les problèmes sauf un que j'ai illustré par ce petit bout de code :
test.php :
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
| function go(){
var xhr_object = null;
if(window.XMLHttpRequest) // Firefox
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // Internet Explorer
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
else // XMLHttpRequest non supporté par le navigateur
{
alert("Sorry, Your browser doesn't support XMLHttpRequest");
return false;
}
xhr_object.open("POST", "alert.php", true);
xhr_object.onreadystatechange = function()
{
if(xhr_object.readyState == 4)
eval(xhr_object.responseText);
}
xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var data = "insert_id="+38
+"&change_id="+39;
xhr_object.send(data);
} |
alert.php :
Code:
1 2 3 4 5 6 7 8 9
| <?php
function alert($msg){
echo '<script language = javascript>';
echo 'alert('.$msg.');';
echo '</script>';
}
alert('insert vaut : '.$_POST['insert_id'].' et change vaut : '.$_POST['change_id']);
?> |
Mon alert ne s'affiche pas et le debugger me renvoi un "invalid XML attribute value" au niveau du "= javascript". Savez-vous pourquoi ?
Merci