【发布时间】:2015-08-27 13:07:52
【问题描述】:
我正在尝试使用 jQuery 从 javascript 调用服务器端函数。
AJAX
function addAsset() {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "ServerMethods.aspx/AddAsset",
data: '{}',
dataType: "json",
success: function (response) {
alert(response);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
});
}
ServerMethods.aspx.vb
Public Class ServerMethods
Inherits System.Web.UI.Page
<System.Web.Services.WebMethod()> _
Public Shared Function AddAsset() As String
Return "Hello"
End Function
End Class
ServerMethods.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ServerMethods.aspx.vb" Inherits="AssetManager.ServerMethods" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
addAsset() 在单击按钮时被调用。当我尝试将 dataType 更改为 text 时,整个 HTML 代码会返回到 ServerMethods。如果 dataType 设置为 json,则会抛出错误“SyntaxError: Unexpected token
有什么想法吗?
【问题讨论】:
标签: javascript jquery json vb.net