Cod: Selectaţi tot
<!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=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">
function post_data(){
var xml = new XMLHttpRequest();
var php = "test.php";
var nume = document.getElementById("nume").value;
var mesaj = "nume="+nume+"&prenume="+prenume;
xml.open("POST", php, true);
xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xml.onreadystatechange = function(){
if(xml.readyState == 4 && xml.status == 200){
var data = xml.responseText;
document.getElementById("mesaj").innerHTML = data;
}
}
xml.send(mesaj);
}
</script>
</head>
<body>
<div id="mesaj">mesaj</div>
<input type="text" name="nume" id="nume" />
<input type="submit" value="trimite" onclick="javascript:post_data();" />
</body>
</html>
Fisierul test.php nu contine decat:
Cod: Selectaţi tot
<?php
echo 'ok';
?>
M-am documentat de pe un tutorial pe care il am pe hartie. Ideea e ca nu functioneaza (nu afiseaza ok). Am imprimat si acest cod si l-am comparat cu cel de pe care m-am ghidat si nu vad unde e gresala. Imi puteti spune unde am gresit?
Am folosit var xml = new XMLHttpRequest(); pentru ca folosesc chrome.