I currently use jQuery to send data from my html forms then I use php to store it in my database. Here is the code I use:
HTML FORM :
<form id="formpost" action="" method="post" onsubmit="return false">
<input type="text" id="text2" name="status" value="" class="form-control" placeholder="Question....?"/><br/>
<textarea id="text1" name="status2" value="" class="form-control" placeholder="Description....." rows="6"></textarea><br/>
<button id="postbutton" class="btn btn-danger">POST</button>
</form>
jQuery File:
$ (document).ready(function() {
//mama code
$("button#postbutton").click(function() {
var data = $("#formpost").serialize();
$.ajax({
type: "POST",
url: "data.php",
data: data,
success: function(data) {
location.reload();
}
});
});
});
$ (document).ready(function() {
$.ajax({
type: "POST",
url: "data2.php",
success: function(data) {
$("#statustext").append(data);
}
});
});
I have two ajax request, data.php sends the html form inputs into my database and data2.php retrieves that data on success and appends an empty html div.
My problem altogether was that I had a working application but when I installed a text-area editor my content from my html forms was not storing into my database. So if I use clean JavaScript the application would run. Any code in clean javascript would be appreciated to send data from my html form using ajax calls. Thanks
Aucun commentaire:
Enregistrer un commentaire