我使用的是ASP.net 3.5。使用JQuery对data方法的调用返回有效的JSON数据。但是,当我使用datatables.net JQuery插件调用相同的webmethod来填充html表时,我会得到页面的整个html。
**WebMethod:**
<WebMethod()> _
Public Shared Function GetData() As String
Dim a As String = "{""aaData"": [['Trident','Internet Explorer 4.0']]}"
Return a
End Function
**Successful JQuery call:**
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "Default2.aspx/GetData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
}
});
});
});不成功的JQuery调用:
$(document).ready(function() {
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "Default2.aspx/GetDate",
"fnServerData": function(sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"url": sSource,
"data": aoData,
"success": fnCallback
});
}
});
});对于第二个调用为什么返回html有什么想法吗?我尝试将contentType:"application/json;charset=utf-8“添加到第二个ajax调用中。我犯了个错误。
发布于 2009-12-17 06:52:34
可能您正在调用一个不存在的方法,因此可能会出现一个错误页面来响应。最好检查一下你的回复是怎么回事。
"sAjaxSource": "Default2.aspx/GetDate",在成功的调用中,您正在使用GetData方法
url: "Default2.aspx/GetData",在不成功的调用中,您将调用GetDate方法。
https://stackoverflow.com/questions/1919330
复制相似问题