I'm having problems with passing variables from jQuery into PHP. I search for the solutions on the internet, and i came to the AJAX. Never used Ajax before, so i guess that the problem is known.
So i have the following code in "index.php"
$("#inviteForm").submit(function(e) {
e.preventDefault();
var emailVal = $("#email").val();
$.ajax({
type: "POST",
url: "processAjax.php",
data: {email: emailVal},
success: function(data) {
alert(data);
}
});
});
In form, i have one input box (for email) and a submit button (the method is POST).
In processAjax.php i have the following code
<?php
$x = $_POST['email'];
return $x;
?>
So if i'm correct, if the $.ajax function is OK, the alert box should pop up. But it doesn't. i've also tried alert(x); but it didn't work.
Any idea what i'm doing wrong
submitevent handler too early (before the form exists); if that's the case take a look at the.ready()function.datavariable.