【发布时间】:2010-08-04 00:08:18
【问题描述】:
我正在使用 jQuery 来使用我构建的 Web 服务,输入当前是序列化的 JSON,以及通过 jQuery AJAX 的输出。
我想通过添加 URI 查询字符串参数使服务更加 RESTful,以便用户在将 URI 保存为他们的状态时可以访问相同的搜索结果页面、查询字符串等。
我认为我的网络服务不需要太多改变。我应该使用 jQuery 访问和重写 URI 吗?如果是这样,是否有人有任何帖子演示如何做到这一点?
谢谢
网络服务:
/// <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) {
【问题讨论】: