Webservice in jQuery returns collection type

I have ASP.NET WebService that returns a List object

public class Students
{
    public string StudentName { get; set; }
     public int Age { get; set; }

}

      

I am accessing this webservice with this jQuery code

$.ajax({
type: "POST",
url: "/Students.asmx/GetStudents",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) { 
$("#myDiv").html(msg.d);
}
});

      

But all I get is an Object.

How can I get the data in this object?

+1


a source to share


1 answer


All objects [Object object] in jquery (when you check the jQuery object).

You actually get an array of Student objects; you can iterate over results like this



for (x = 0; x < msg.length; x++) {
    alert(msg[x].StudentName);
}

      

+1


a source







All Articles