2

I have some <li> Items in my HTML Page like this

<li id="A1" class="ui-state-default">Item 2</li>
  <li id="A2" class="ui-state-default">Item 3</li>
  <li id="A3" class="ui-state-default">Item 4</li>
  <li id="A4" class="ui-state-default">Item 5</li>

I called It using Javascript and Jquery like this to get the Id and Index of the <li> elements

function LiOrder() {
            var order = $('li').map(function (i) {
                return { id: this.id, index: i };
            }).get();

            PageMethods.GetServerResponse(order, OnSuccess, OnFail);
        }

        function OnSuccess(arg) {
            alert(arg);
        }

WebMethod Written in Aspx.cs Page is this

[WebMethod]
    public static string GetServerResponse(string[,] LiOrder)
    {


        return LiOrder[0,0];
    }

But when I try to execute it I get Error like this in Google Chrome (Javascript Console)

POST http://localhost:2453/ERP29.1.13/Production/LifeCycleRegistration.aspx/GetServerResponse 500 (Internal Server Error) ScriptResource.axd:6979

What might be the reason for this error. I could pass a string to WebMethod like this. But when it comes to Array, its like this. Please Help me to resolve this

7
  • use string only. it's not multi dimension array. Commented Mar 8, 2013 at 10:07
  • Can't we pass Array to PageMethods Commented Mar 8, 2013 at 10:07
  • While debugging It showed me as an Array. Commented Mar 8, 2013 at 10:09
  • whatever you send it will be string or object in javascript. you can json.stringfy, and send the string to method Commented Mar 8, 2013 at 10:11
  • Tried with string too. Nothing changes Commented Mar 8, 2013 at 10:11

1 Answer 1

2

JSON.stringfy resolved my issue. I changed my code like this

var LiArr=JSON.stringify(order);
            PageMethods.GetServerResponse(LiArr, OnSuccess, OnFail);
Sign up to request clarification or add additional context in comments.

1 Comment

Hi. I've faced with the same problem. But your solution doesn't work for me. My jquery and c# method exactly the same with yours. But JSON.stringify makes my array a string. I need multidimensional array of data. Do you know why it is happening?

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.