2012-02-21 65 views
1

我有這個寧靜的web服務,其實我在c#中返回列表<>。現在我需要使用jquery和ajax來訪問它(這部分完成)我沒有做的事情,我不能做的是如何遍歷數據並在jquery一側逐一打印。任何幫助都感激不盡。更新:在我的休息Web服務上有這個代碼。你能給我一個$ .each函數的示例代碼嗎?因爲我似乎無法使它工作。謝謝。訪問並從平靜的web服務返回數據到jquery

 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; 
    } 

回答

0
+0

我需要序列化它嗎?因爲我已經在它上面有一個webMessageFormat.JSON的responseFormat,所以在瀏覽器中它將它作爲json返回。我可以問$ .each()的特定代碼嗎?謝謝。 – jongbanaag 2012-02-21 01:51:59

+0

'$ .each(your_collection,function(i,collection_item){alert(collection_item)}' – cszy 2012-02-21 01:57:42

+0

主席先生,我可以請求我的編輯代碼嗎?因爲這個代碼(基於你的)$ .each(result,function我,val){alert(val);});不起作用。 – jongbanaag 2012-02-21 02:22:37