[英]Access and return data from restful webservice to jquery
我有这个宁静的Web服务,实际上我在C#中返回一个list <>。 现在,我需要使用jquery和ajax(完成此部分)访问它,而我不能做的是如何遍历数据并在jquery一侧逐一打印。 任何帮助都感激不尽。 更新:在我的其余Web服务上有此代码。 您能给我$ .each函数的示例代码吗? 因为我似乎无法使其工作。 谢谢。
List<Inventory> IService1.GetInventory()
{
List<Inventory> list = new List<Inventory>(); using (SqlConnection testconn = new SqlConnection(connection))
{
if(testconn.State == ConnectionState.Closed)
{
testconn.Open();
}
using(SqlCommand testcmd = new SqlCommand("select * from inventoryitem",testconn))
{
SqlDataReader reader = testcmd.ExecuteReader();
while( reader.Read())
{
Inventory testObj = new Inventory();
testObj.InventoryName = reader["StandardCost"].ToString();
list.Add(testObj);
}
}
}
return list;
}
您应该能够将其序列化为JSON:
http://msdn.microsoft.com/zh-CN/library/system.web.script.serialization.javascriptserializer.aspx
然后在jQuery中使用$ .each()对其进行迭代。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.