the form:
<form action="" id="register" method="post"> <input type="text" placeholder="eg. John"> <input type="text" placeholder="eg. Appleseed"> <input type="text" placeholder="youremail@domain.com"> </form>
JS:
$('form#register').on('submit',function (e) { $.ajax({ url: 'submit.php', cache: false, type: 'POST', context: this, data : $(this).serialize(), success: function(json) { console.log("json: " + json); } }); e.preventDefault(); });
PHP:
$formData = json_encode($_POST); echo print_r($formData,1);
... after filling out the form and clicking submit, it submits the form without error, but the returned data (JSON) is empty:
json: []
What am I doing wrong?
json javascript jquery ajax php
3zzy
source share