Question

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

Was it helpful?

Solution

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

var LiArr=JSON.stringify(order);
            PageMethods.GetServerResponse(LiArr, OnSuccess, OnFail);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top