r p

r p

  • NA
  • 343
  • 0

How to create an array in jquery using Class Objects return

Nov 20 2013 11:07 AM
I am trying to create an array using the Class Objects I receive from a web service call.
I want to create an arrray called data.
My code looks like this; but it is not working.
I don't know where I am going wrong.

var data = [];

$(document).ready(function () {
    $.ajax({
        type: "POST",
        url: "MyWebService.asmx/GetMyClassObjects",
        data: "{ val1: 'val1', val2: 'val2' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            var myData = data.d;
            for (var i = 0; i < myData.length; i++) 
            {
                data.push

               (

             { id: myData[i].id, fname: myData[i].Fname, lname: myData[i].Lname}

             );

            }
        }
    });
});


Thanks for your help.

Answers (2)