Home > DeveloperSection > Forums > How to posting data from Jquery Form
Ashish Pandey

Total Post:128

Points:898
Posted on    February-05-2015 10:31 PM

 ASP.Net JQuery  Web 
Ratings:


 1 Reply(s)
 528  View(s)
Rate this:

I have a simple jquery form which gets the input from user and posts the data to another page and displays a success message. But my problem is the data doesn't get posted to the other page, instead the error message gets popped up.

Here is my Jquery:

 $(document).ready(function () {

     $("#register").click(function () {

    var name = $("#name").val();

    var email = $("#email").val();

    var password = $("#password").val();

    var cpassword = $("#cpassword").val();

    if (name == '' || email == '' || password == '' || cpassword == '') {

        alert("Please fill all fields...!!!!!!");

    } else if ((password.length) < 8) {

        alert("Password should atleast 8 character in length...!!!!!!");

    } else if (!(password).match(cpassword)) {

        alert("Your passwords don't match. Try again?");

    } else {

 

            $.ajax({

 

            type:"POST",

            url: "SignUp.aspx/register",    //trying to post to this url

            data: { firstName: name },

 

            success: function (msg) {

                alert("Success");        // Success message which should pop up if successful

            },

            error: alert("Failed")       //error message which should pop up if there is an error

        });

    }

});

});

Here is the code in signup.aspx page (code behind class):

         public string register(String firstName)

         {

            return "Success";           

         }

The url i have provided is correct there is no problem with that. What might be the problem here ?

Also are there another methods to send data to another page?

Thank you for your time



Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    February-05-2015 10:55 PM

This

        success: function (msg) {

            alert("Success");        // Success message which should pop up if successful

        },

        error: alert("Failed")       //error message which should pop up if there is an error

    });

Should be:

        success: function (msg) {

            alert("Success");        // Success message which should pop up if successful

        },

        error: function(){alert("Failed")}       //error message which should pop up if there is an error

    });

You could have additional errors though.


Don't want to miss updates? Please click the below button!

Follow MindStick