Submitting Form Via Jquery Ajax Post Request
I have a basic messaging service on a web Node / Express web app, and I'm trying to submit the form via Ajax, using the FormData object. If I submit the form without AJAX, then eve
Solution 1:
This is the html part
<form id="form" action="" method="post">
<input type="text" name="msgID"id="msgID">
<input type="text" name="senderId"id="senderId">
<input type="text" name="senderName"id="senderName">
<input type="text" name="recipientId"id="recipientId">
<input type="text" name="recipientName"id="recipientName">
<input type="submit" name="dsq" value="dsqdsq">
</form>
this is the JavaScript part
<scripttype="text/javascript">
$(document).ready(function(){
$("#form").submit(function(){
$.ajax({
url: "test.php",
data: $("#form").serialize(),
type: "POST",
dataType: 'json',
success: function (e) {
console.log(JSON.stringify(e));
},
error:function(e){
console.log(JSON.stringify(e));
}
});
returnfalse;
});
});
</script>
And this is the php code
<?phpdie(json_encode(array("status"=>true)));
?>
Hope that will helps you.
Solution 2:
I checked your code it says that's
Illegal invocation
So i'll give a solution you can use
data: $form.serialize(),
dataType:'json',
And then you can catch your returned result by
console.log(JSON.stringify(e));
Wish that helps. If you have some errors i can help you.
Post a Comment for "Submitting Form Via Jquery Ajax Post Request"