1

I am using ajax for first time,not able to solve this problem here is the code fr.php

<script type="text/javascript">

    function register(){

        $.ajax({

            type: "POST",
            url: "submit_data.php",
            data:     "username=" + document.getElementById("username").value + 
                    "&email=" + document.getElementById("email").value,
            success: function(html){
                $("#response").html(html);
            }
        });
        }

    </script> 

and my problem is its not going inside the function also on button click

4
  • In the php script have you put a var_dump(); to see if data is passed correctly? What is the script`s response? Commented Oct 15, 2012 at 7:09
  • What is the exact problem? Aren't you getting the post data? Commented Oct 15, 2012 at 7:10
  • Where the submit_data.php code? What's the problem - are you getting an error , the database doesn't get updated? Commented Oct 15, 2012 at 7:11
  • print_r the post data in your php file and report the output Commented Oct 15, 2012 at 7:16

3 Answers 3

2

You are not sending data in a correct way.

Below is your modified code

<script type="text/javascript">
function register(){
    $.ajax({
        type: "POST",
        url: "submit_data.php",
        data: { "username": document.getElementById("username").value, "email": document.getElementById("email").value },
        success: function(html){
            $("#response").html(html);
        }
    });
}
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

you are sending data in wrong way. Use this code for sending data correctly

data: { "username": document.getElementById("username").value, "email": document.getElementById("username").value },

4 Comments

on button click i have called the function but its not working <input type="button" name="submit" id="submit" value="Subscribe" onclick="register()"/>
@shilpa try alert inside this function and use console also that function is calling or not.
i have used alert after this line $.ajax({ ..but its not working
can you please elaborate ..how to check it m not getting
0

agree with Yogesh Suthar additionally if you are using jQuery your code better look like this:

<script type="text/javascript">

    function register(){

        $.ajax({
            type: "POST",
            url: "submit_data.php",
            data: { username: $("#username").val(), email: $("#email").val() },
            success: function(html){
                $("#response").html(html);
            }
        });
    }

</script>

Comments

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.