簡體   English   中英

從靜態Web服務訪問數據並將其返回到jquery

[英]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()對其進行迭代。

http://api.jquery.com/jQuery.each/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM