tags:

views:

91

answers:

1

I have an ASP.NET WebService that returns an object of List

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

}

I am accessing this webservice using 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 Object object.

How can I get the data in that object?

+1  A: 

Everything is [Object object] in jquery (when you inspect a jQuery object).

You are actually getting an array of Student objects; you can iterate through the results like this

for (x = 0; x < msg.length; x++) {
    alert(msg[x].StudentName);
}
Juan Manuel
Thanks so much..I forgot to mention that I am using jmsajax and not the $.ajax ..so when I do what you suggest..i get d.length is null or not an object.
Musa
Here;s the library i am using http://schotime.net/jMsAjax.aspx
Musa
I solved it..it should be msg.length ..thanks
Musa
Glad you got it working
Juan Manuel