mardi 24 mars 2015

My ajax form is not submitting

Yesterday I was advised by another user to start looking into Ajax coding to improve my application development skills.


I was testing form submissions. However My form is not submitting. I am only new to ajax so I have been following some tutorials on how to do ajax online so any help would be appreciated.



<html>
<script type="text/javascript" src="../scripts/jquery.1.11.2.min.js"> </script>
<form id="form" action="" method="POST">
<textarea id="question" name="question" style="width: 200px; height: 200px; resize: none;"></textarea>
<button id="formsubmit"> Submit</button>
</form>
<textarea id="response" style="width: 200px; height: 200px; resize: none;"></textarea>
<script>
$(document).ready(function(){
$('#formsubmit').on("click",function(){
$.post("submit.php", { question: $('#question').val() }, function(data) {
$('#response').html(data);
});
});
});
</script>
</html>


My goal here is to get the user input and show it in a textarea beneath it. I don't want the page to refresh.


My php code to process this is :



<?php
$q = $_POST['question'];
echo $q;
?>

Aucun commentaire:

Enregistrer un commentaire