How to pass a variable from js file to php file.i want variable from checker.js
to test.php
function SendData(id){
$.ajax({
type: "POST",
url: "test.php",
data: "id=" + id,
cashe: false,
success: function(response){
alert("Record successfully updated")
}
})
}
$(document).ready(function(){
SendData(10)
})
test.php file
<?php
var_dump($_POST);
?>
index.html
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="checker.js"></script>
</head>
<body>
</body>
</html>
Try this and see what is logged in your console:
I am almost certain something is being returned by the server, you’re just not looking for it.
If you want to retrieve your ID, you could change your php to:
and your js to: