Pass Variables From Javascript To Php File To Store Them In Mysql Db After
Im trying to add a new functionality to my web application. I want the user to be able to select the dates and time they can actually work. For that I create a calendar where I can
Solution 1:
Either with Ajax or you can wrap your inputs with a <form action=your_php_file.php>
and post/get them to the php script
Solution 2:
Post to your php script using an AJAX call and then, in your php script, access the parameters via the $_POST array, ie:
Code to post to your php script (insert the code in your JS file):
$.ajax({
url: "/subdirectory/model.php",
type: "POST",
data: {
day: "friday",
start: "07:00:00",
end: "16:00:00"
}
})
.donefunction(data)({
console.log(data)
})
.failfunction()({
console.log("Parameters failed to be sent to php!")
})
Code to access the parameters passed from JS in /htdoc/subdirectory/model.php:
<?php
var_dump($_POST);
?>
Executing your JS should result in the three sample parameters being displayed in your browser's log. For you db, instead of vardumping $_POST, you'll add code to the php script that writes the variables to your db.
Post a Comment for "Pass Variables From Javascript To Php File To Store Them In Mysql Db After"