0

dear all i want to know how to submit asp.net form data using jquery ajax functionality and how im get that json data in the server side

?

1
  • 6
    Dear you ... this is not a Generate-Code Forum, shows us what have you tried, what have you tested and then we will help you with some code if you're stuck... Commented Sep 30, 2011 at 8:55

2 Answers 2

2
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$("#<%=btnSubmit.ClientID %>").click(
  function()
  {
    $.ajax
    ({
         type: "POST",
         contentType: "application/json; charset=utf-8",
         url: "Default.aspx/AcceptFormData",
         data: "{'funcParam':'"+$('#formName').serialize()+"'}",
         dataType: "json",
         success: function(msg)
         {
              var msgFromASPXFunction = msg.d
         }
     });
  }
 );
});


[System.Web.Services.WebMethod]
public static string AcceptFormData(string funcParam)
{
  // this is your server side function
  //the data you will get will be in format e.g. a=1&b=2&c=3&d=4&e=5 inside funcParam variable
  return "Data Submitted";

}

Just note the server-side function name should match the parameter you specified in the url property of $.ajax function of jQuery. (In above case it is "AcceptFormData"

Also the parameter name should be same as of the server side function parameter. In this case it is "funcParam".

Just compare the $.ajax and server-side function in this code.

Regards,

Amin Sayed

(Note: Please mark if it is helpful)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you a lot For your Post could you please Explain me Below Code Fraction data: "{'funcParam':'"+$('#formName').serialize()+"'}",
This is a parameter to your C# function passed from the javascript, whenever you try to call the Ajax (in this case at the time you submit). You can see 'funcParam' name matches the parameter of your C# function AcceptFormData. You need to make sure these two match.
1
<form action="#" id="example-form">

...

</form>

<script type="text/javascript">

    $('#example-form').submit(function(){

        // block form

        $.post('putUrlHere', $('#example-form').serialize(), function(data) {
            //call back happens here.  Unblock form/show result
        });

        return false; // this prevents regular post, forcing ajax post.

    });

</script>

REFERENCE : http://forums.asp.net/t/1611677.aspx/1?Jquery+with+ASP+NET+Form+submit

Otherwise Check : jquery + ajax combine..... http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

3 Comments

Thanks sikender but how can i grab the client side para meters from server side
i want to know how can i call specific asp.net server method from jquery and how can i grab that parameters?
you can use json for calling webmethod.

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.