I have a very simple php page with a jquery function
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: "test.php",
type: "POST",
data: {
myvar: 1,
},
success: function(result) {
console.log("it works");
}
});
});
</script>
My AJAX function is supposed to be triggered as soon as the document is ready. My test.php just shows my $_POST
.
<?php
var_dump($_POST);
die();
Nothing is happening. I should go to test.php and see the var_dump. It works if I have a button and start the AJAX function on the click but not like that… Isn’t possible to do so ?
2
Answers
I test your code work with datatype like :
ajax page:
Since on the Back-end part you expect
$_POST
the best you can do is to useFormData API