I'm trying to submit some form data using jQuery / Ajax to a PHP web service (php file) and simply echo the results, for now.
Here is my index.html file
<html>
<head>
<title>PHP web service & AJAX</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<h1>Hello! Is it me you're looking for?</h1>
<form id="submit">
<label>Name</label>
<input id="name" type="text" name="name" />
<label>Email</label>
<input id="email" type="email" name="email" />
<input class="submit" type="submit" value="Submit details" />
</form>
<script type="text/javascript">
$(document).ready(function(){
$(".submit").click(function(e) {
e.preventDefault();
// BUILD DATA STRING
var name = $("#name").val();
var email = $("#email").val();
var dataString = "subName=" + name + "&subEmail=" + email;
$.ajax({
type: 'POST',
url: 'results.php',
data: dataString,
success: function() {
window.location.href = "results.php";
}
});
});
});
</script>
And the PHP (results.php) file
<?php
echo $_POST['subName'] . "<br />" . $_POST['subEmail'];
?>
Having no luck so far, can anyone help me out? I've tried this tutorial and this one as well but they haven't helped.