1

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.

3
  • you might want to use GET instead of POST Commented Mar 29, 2013 at 9:24
  • 1
    What is the problem, please elaborate it. Commented Mar 29, 2013 at 9:25
  • possible duplicate: stackoverflow.com/questions/1184624/… Commented Mar 29, 2013 at 9:27

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

6 Comments

on clicking the submit button it is taking the browser to localhost/realbhs/process/…
Did you include jQuery? Open the console (F12) and look for errors.
@TangoTango - You're using a version of jQuery that is too old, it's on 2.0 now and you're using a version below 1.7.
I Am using 1.9.1 which version should i use ? i cant find the 2.0 version
In 1.9.1 this is not an issue, but if .on() does'nt exist you are using an older version.
|
0
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.

Comments

0

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...

2 Comments

so you take everything in session before storing it into database ? That's horrible
Yes, and we usually create our own session we call it ( SessionFacade) . but the way above is also a good way to pass those values from one page to another ( create multiple sessions according to the number of fields and use them in that page where the database functions are in. Then reset the session. and I think what you need is just passing values form one page to anther.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.