Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing array from jquery ajax method to c# codebehind
    primarykey
    data
    text
    <p>I need to pass a JavaScript Array variable to a code-behind file and access that array.</p> <p>Please let me know if this is the exact data object that the Ajax method would expect. While using this, the code always jumps to <code>failureCallback</code> function. Can anyone please help me with this?</p> <p><strong>jQuery/JavaScript:</strong></p> <p>The data in the <code>result</code> array is: <code>section_1,section_2,section_3</code>.</p> <p>The output of <code>paramList</code> is: <code>{"data":"section_1,section_2,section_3"}</code>.</p> <pre><code>function generateData() { var result = $('#accordion').sortable('toArray'); alert(result); ExecutePageMethod("ReorderList.aspx", "HandleData", ["data", result], successCallback, failureCallback); } function ExecutePageMethod(page, fn, paramArray, successFn, errorFn) { alert("entered page method"); var paramList = ''; if (paramArray.length &gt; 0) { for (var i = 0; i &lt; paramArray.length; i += 2) { if (paramList.length &gt; 0) paramList += ','; paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"'; } } paramList = '{' + paramList + '}'; alert(paramList); $.ajax({ type: "POST", url: page + "/" + fn, contentType: "application/json; charset=utf-8", data: paramList, dataType: "json", success: successFn, error: errorFn }); } function successCallback(result) { var parsedResult = jQuery.parseJSON(result.d); } function failureCallback(result) { alert("entered failure"); } </code></pre> <p><strong>C# Code Behind:</strong></p> <pre><code>public static string HandleData(object[] data) { //How should I parse this object data? return data; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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