Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have implement something like this before which is passing an array to web method. Hope this will get you some ideas in solving your problem. My javascript code is as below:-</p> <pre><code> function PostAccountLists() { var accountLists = new Array(); $("#participantLists input[id*='chkPresents']:checked").each(function () { accountLists.push($(this).val()); }); var instanceId = $('#&lt;%= hfInstanceId.ClientID %&gt;').val(); $.ajax({ type: "POST", url: "/_layouts/TrainingAdministration/SubscriberLists.aspx/SignOff", data: "{'participantLists': '" + accountLists + "', insId : '" + instanceId + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { AjaxSucceeded(msg); }, error: AjaxFailed }); } </code></pre> <p>In the code behind page (the web method)</p> <pre><code> [WebMethod] public static void SignOff(object participantLists, string insId) { //subscription row id's string[] a = participantLists.ToString().Split(','); List&lt;int&gt; subIds = a.Select(x =&gt; int.Parse(x)).ToList&lt;int&gt;(); int instanceId = Convert.ToInt32(insId); </code></pre> <p>The thing to notice here is in the web method, the parameters that will receive the array from the ajax call is of type object.</p> <p>Hope this helps.</p> <p>EDIT:- according to your web method, you are expecting a value of type boolean. Here how to get it when the ajax call is success </p> <pre><code> function AjaxSucceeded(result) { var res = result.d; if (res != null &amp;&amp; res === true) { alert("succesfully posted data"); } } </code></pre> <p>Hope this helps</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload