HOW TO POSTING DATA FROM JQUERY FORM

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
JQuery  Web 
 1136  View(s)
Ratings:
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

  1. Manoj Bhatt

    Post:154

    Points:1086
    Re: How to posting data from Jquery Form

    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.

      Modified On Apr-09-2018 01:19:31 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!