I've been trying for a few hours already, and I don't know what else to try. I looked at dozens of questions around here, but they're overly-complicated or I don't understand them. Doesn't help that my experience with javascript/jquery dates to a few days ago. Anyways, here's my form:
<form onsubmit="onSubmit(this)">
<input type="text" name="input1"/><br/>
<input type="text" name="input2"/><br/>
</form>
And my script:
function onSubmit( form ){
var jsondate = JSON.stringify( $(form).serializeArray() );
console.log( jsondate );
alert(jsondate);
$.ajax({
type: "POST",
url: "json.php",
data: jsondate,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){
alert(jsondate);
},
failure: function(errMsg) {
alert(errMsg);
}
});
}
And my json.php file:
<?php
if (isset($_POST['jsondate'])) {
echo "whatever";
}
The thing is, I get the alert with the json string, but when it redirects me to json.php (using action="json.php"
on the form), or I stay on the page, it doesn't show anything, so I guess it's something inside $.ajax({...})
Any explanation about how to make it work, how it works and why would be REALLY helpful!