My first post here. I am new to Java/AJAX, but I have some experience in PHP. I am trying to pass html form data to a php file for processing. The goal is to have the php script process the form data and return a true/false flag. I am trying AJAX as I dont want a screen refresh. Based on the response from the php script a popup will overlay the existing screen with information to the user.
My HTML form code is:-
<form name="screen3" method="post" action="" id="scr3" />
<input type="image" src="images/proceed.jpg" alt="Proceed" id="proceed1" name="submit" value="Send" />
</form>
I have redirected the submit button from the form using javascript:-
<script type="text/javascript">
$(document).ready(function() {
$('#proceed1').click(function(e) {
e.preventDefault();
x=validateScreen3();
if (x) {getFormData();}
})
});
</script>
So far so good, validateScreen3() is called and validates the users entry (wont bore you with the script). getFormData is called but that is where the problem lies:-
function getFormData() {
var xmlhttp;
var emailAddress = document.getElementById("emailaddress").value;
var entryCode = document.getElementById("entrycode").value;
var acceptance = document.getElementById("acceptance").value;
var Sel = document.getElementById("sel").value;
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","test1.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("emailaddress="+emailAddress);
}
I've confirmed that the variable data is getting passed to the function ok, but the test1.php script referenced above doest seem to be being called/executed. Here is the test1.php file:-
<?php
$here = $_POST['emailaddress'];
echo '</div></div>';
if (!empty($here)) {
echo '<div style="position:absolute; top:100px; left:300px; width:400px; height:200px; background-color:#CCC; color:#000; z-index:50;">';
echo 'got the variable '.$here;
echo '</div>';
}
else {
echo '<div style="position:absolute; top:100px; left:300px; width:400px; height:200px; background-color:#CCC; color:#000; z-index:50;">';
echo 'DIDNT GET the variable '.$here;
echo '</div>';
}
?>
Neither of these div's are showing up and from every test I can think of, the file is simply not being called. Any ideas or suggestions would be greatly appreciated.
==
), they're completely different languages – Elias Van Ootegem Jun 7 '13 at 9:05