[英]WebMethods not working with VS2013
我曾经在VS2010中从jQuery调用WebMethods的做法不再适用于VS2013。 这是页面服务代码:
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Web.Script.Serialization
<WebMethod()> _
Public Shared Function Test() As String
Dim strTest As String = "Testing"
Return strTest
End Function
这是调用方法的jQuery:
function TestService() {
$.ajax({
type: "POST",
url: "myPage.aspx/Test",
contentType: "application/json; charset=utf-8",
data: '[]'
})
.done(function (d) {
alert('success');
})
.fail(function (xhr, st, err) {
alert('failed');
});
}
而且你可以猜到我总是得到失败的警报。 这在2010年完美无缺。在文档中找不到任何新内容。
参数data: '[]'
不是字符串而是对象。 您必须将其更改为:
data: { myproperty: 'value' }
或者只是删除数据参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.