【发布时间】:2012-02-20 00:09:18
【问题描述】:
使用 Asp.Net 4.0 Web 表单和 Jquery 1.6.2。 我想对页面上的 WebMethod 进行 Ajax 调用并让它返回 html。 在服务器端,WebMethod 看起来像这样。
[WebMethod]
public static string GetOrders()
{
return theMethodThatGeneratesHtml();
}
这里是调用 Ajax 函数。
function GetOrders()
{
$.ajax({
type: 'POST',
contentType: "application/json",
url: "Orders.aspx/GetOrders",
data: "{}",
success: function (data) {
$('#content').html(data);
},
dataType: "text"
});
}
从 WebMethod 返回的数据总是被包装成一个像这样开始的 json 对象。
{"d":"\u003ctable\u003e\r\n ........
如何让 WebMethod 只返回 HTML?
【问题讨论】: