using jquery to read an Asp.net arraylist
I have a web method in ASP.net which it's output is an ArrayList and read cities from databse. this web method is called using jquery.
$.ajax(
{ url: "../AjaxServices/StateCity.asmx/showcity",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
data: '{s: ' + $('#<%=DpState.ClientID%>').val() + '}',
success: function(data) {
}
I wanna know how to loop through data
,开发者_StackOverflow社区 because the data is object.
I knew about
jQuery.each( collection, callback(indexInArray, valueOfElement) )
but doesn't work
When you call an ASP.Net WebMethod using AJAX, it returns an object with a d
property containing your data.
If your WebMethod returns a collection, you can write
$.each(data.d, function(index, obj) { ... });
Slaks answer is great a ndI found a solution base on SLaks answer, so I'll share it here:
just take care about Value
and Text
they're case sensitive.
success: function(data) {
$.each(data.d, function() {
alert(this['Value'] + ':' + this['Text']); }) }
精彩评论