I have been having this trouble for several days and at my wits end now, I am frustrated! I tried making an ajax call to a script using jQuery's
post
method but it posts nothing and does not touch the script. I had
$.post('server_script.php', $("form").serialize());
and after trying repeatedly, it neither touches/runs the script nor returns any errors. Any functions placed in the
done
method often run still the php script shows it was not touched.
What I have tried:
Now I switched to
.ajax
:
$('form').on("submit", function(){
$.ajax({
type: "POST",
url: "test.php",
data: $("form").serialize()
});
});
test.php
$name = $_POST["name"];
$email = $_POST["email"];
$rand = mt_rand();
echo $name . "\n" . $email . "\n" . $rand;
var_dump($_POST);
The above outputs the `rand` alone and my error log shows undefined index for the rest when I run the script on its own.
I also tried passing the data manually as an object
{email: "vainglory7@gmail.com"}
, didn't work. Tried parsing it as json, didn't work. Please someone help me as I am desperate. I have tried asking friends but no one seems forthcoming and I've been at this for days now