0
我使用jQuery來使用Web服務我建,輸入當前序列化JSON,以及通過jQuery AJAX的輸出。jQuery的創建REST參數消耗web服務
我想使服務更加RESTful的加入URI查詢字符串參數,以便用戶可以訪問搜索結果,查詢字符串,等等,等等的同一頁面一樣,當他們的URI保存爲自己的狀態。
我不相信我的web服務需要大量的變化。我應該使用jQuery訪問並重寫URI嗎?如果有的話,是否有人有任何帖子證明如何做到這一點?
感謝
Web服務:
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public OutputData updateProductsList(InputData request)
{
//...//
return result;
}
而且使用JSON序列化的Ajax請求:
//Build the ajax Request
var req = { request: { qtype: "ProductName", query: queryText, page: resultPage, rp: rP} };
$.ajax({
type: "POST",
url: "/webservice/WebService.asmx/updateProductsList",
data: JSON.stringify(req),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
嗯,我想我跟着,我需要改變我從頁面獲取輸入數據接受URI數據的方式嗎? 也是我仍然使用JSON發送數據?或者它是一個表單文章? – 2010-08-04 19:49:18
@ jordan.baucke:正如我所說,我不能說很多關於Web服務的知識,我甚至不知道這是什麼語言;)如果用戶應該能夠爲頁面添加書籤,則必須從POST更改爲GET ('type:GET')並使Web服務接受這些參數。如果您將數據傳遞給Ajax調用,jQuery將調用URL'/webservice/WebService.asmx/updateProductsLis?qtype = ...&query = ...&''。 – 2010-08-04 20:09:08
感謝Felix我結束了使用:jQuery BBQ http://benalman.com/code/projects/jquery-bbq抓取參數並重寫URI。 如果我想提供更直接的訪問我的網絡服務,我會更新它。 – 2010-08-05 04:22:23