i have this restful web service where i actually return a list<> in c#. Now i need to access it with jquery and ajax(this part done) what i haven't and i couldn't do is how to traverse the data and print it one by one on the jquery side. Any help will be much appreciated. UPDATE: having this code on my rest web service. Can you give me a sample code for the $.each function? because i can't seem to make it work. THANK YOU.
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;
}
You should be able to Serialize it as JSON:
http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
Then iterate over it with an $.each() in jQuery.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.