I wrote a detailed example of this using ASP.NET MVC, but it can be easily adapted for WebForms.
Send data using jquery to MVC controller
HTML and jQuery will look almost exactly the same, except where you call WebMethod.
If the page you are using is called Default.aspx and the method is called Done , then your URL for WebMethod will be Default.aspx/Done .
<script> // Grab the information var values = {"1,","2","3"}; var theIds = JSON.stringify(values); // Make the ajax call $.ajax({ type: "POST", url: "Default.aspx/Done", // the method we are calling contentType: "application/json; charset=utf-8", data: {ids: theIds }, dataType: "json", success: function (result) { alert('Yay! It worked!'); }, error: function (result) { alert('Oh no :('); } }); </script>
Your WebMethod will still match.
[WebMethod] public static void done(string[] ids) { String[] a = ids;
David east
source share