AJAX + PHP help
Here is my form.html
<html>
<head>
<script type="text/javascript">
function ajax() {
var aj;
if(window.XMLHttpRequest) {
aj = new XMLHttpRequest();
}
else {
aj = new ActiveXObject("Microsoft.XMLHTTP");
}
aj.onreadystate = function() {
if(aj.ready == 4) {
document.getElementById("text").innerHTML = aj.responseText;
}
};
var param = document.forms["fo"]["text"].value;
aj.open("GET", "try.php" , true);
aj.send();
}
</script>
</head>
<body>
<form name="fo" method="post">
<input type="text" name="text" />
<input type="submit" onsubmit="ajax()" name="submit" />
</form>
<p id="text">
</p>
</body>
</html>
Here is my try.php:
<?php
echo "this this working";
?>
How come i am not getting a responce back ?
Related Article: View/download Binary files ajax/php
is a solved JavaScript / DHTML / AJAX discussion thread by pucivogel that has 1 reply, was last updated 3 months ago and has been tagged with the keywords: view, download, file, ajax, php.
godzab
Junior Poster in Training
65 posts since Jun 2012
Reputation Points: 0
Solved Threads: 5
Skill Endorsements: 0
Check out this tutorial. There are some errors in your code that need to be fixed.
pritaeas
Posting Prodigy
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86
Its still not working:
<html>
<head>
<script type="text/javascript">
function ajax() {
var aj;
if(window.XMLHttpRequest) {
aj = new XMLHttpRequest();
}
else {
aj = new ActiveXObject("Microsoft.XMLHTTP");
}
aj.onreadystatechange= function() {
if(aj.readyState == 4) {
document.getElementById("text").value = aj.responseText;
}
};
aj.open("GET", "try.php" , true);
aj.send(null);
}
</script>
</head>
<body>
<form name="fo" method="post">
<input type="text" name="text" />
<input type="submit" onsubmit="ajax()" name="submit" />
</form>
<span id="text"> </span>
</body>
</html>
godzab
Junior Poster in Training
65 posts since Jun 2012
Reputation Points: 0
Solved Threads: 5
Skill Endorsements: 0
Question Answered as of 6 Months Ago by
esma.ramirez
and
pritaeas