I am trying to learn basic AJAX and Javascript by following various tutorials and examples on the Internet, but I hit the wall. I am trying to write a simple script to take user input from a form using AJAX and submit it to a PHP script, which then simply re-phrases the input.
All I really can say is that everything that is entered does not work, but I still can not say why. I tried with both POST and GET, and with different data types, with the same result. I’m sure that I’m doing something wrong or misunderstanding something, but I’m not sure what.
HTML / AJAX
<form id="my_form">
word <input type ="text" id="word1"/><br/>
<input type="submit">
</form>
<script>
$(document).ready(function(){
$("#my_form").on(function(e){
e.preventDefault();
var verb = $("word1").val();
$.ajax({
url: "testrun.php",
data: "verb",
type: "POST",
});
});
});
</script>
Php
if (isset($_POST['verb'])){
$x= $_POST['verb'];
echo $x;
}else {
echo "not working";
}
EDIT: , , , . , , AJAX , , - PHP. AJAX/HTML , testrun.php script testrun.php, AJAX, ,
AJAX, , , - , PHP POST? .