Reputation: 13
i want to send all the input fields of the form to process/do_submitattendance.php, where i can use the to store in the database. However i am having trouble doing this. My jQuery code is-
<script type="text/javascript">
$("#submitattendance").submit(function(){
var_form_data=$(this).serialize();
$.ajax({
type: "POST",
url: "process/do_submitattendance.php",
data: var_form_data,
success: function(msg){
alert("data saved" + msg);
});
});
</script>
submitattendance is the ID of the form element.
Upvotes: 1
Views: 287
Reputation: 735
Why don't you try to pass values through session?
By using session you can pass the values from one page to anyother pages you want.
the typical code looks like this:
Mainpage.php
<?php
session_start(); // You should start session
$_SESSION['UserName']="YourTextfield";
?>
SecondPage.php
<?php
session_start();
$var = $_SESSION['UserName'];
?>
After you saved the data...then you need reset the session
$_SESSION['UserName']="";
That's what I usually use. and I hope it will help you...
Upvotes: 0
Reputation: 318182
I'm guessing the form is submitting, and you'll have to prevent the default submit action:
<script type="text/javascript">
$(function() {
$("#submitattendance").on('submit', function(e){
e.preventDefault();
$.ajax({
type: "POST",
url : "process/do_submitattendance.php",
data: $(this).serialize()
}).done(function(msg) {
alert("data saved" + msg);
});
});
});
</script>
Upvotes: 1
Reputation: 11661
var var_form_data=$(this).serialize();
is all i can find, or there must be an error in your code somewhere else. you can look in your chrome console to see if there is an error (f12). also add return false;
to stop the form submitting itself.
Upvotes: 0