I want to use the jQuery ajax method to process a form. In the php script that I call (myScript.php) I'd like to use the GET value that is set by submitting the form within the php script but it is not passing through properly.
<script>
$('#myForm').submit(function(event) {
event.preventDefault();
$.ajax ( {
url: "myScript.php",
success: function (data) {
console.log(data);
}
} );
});
</script>
My form has one field (username):
<form id='myForm' action="" method="get">
Username: <input type="text" id="username" name="username" value="" />
<button id='submitButton' name="">Search</button>
<form>
And finally, my php script will just return back the get value.
<?php
$returnString = array();
$returnString['username'] = $_GET['username'];
echo json_encode($returnString);
?>
The console returns: {"username":null} regardless of what value you type in the input box.