【发布时间】:2017-07-03 19:11:49
【问题描述】:
第一步:
我已将我的脚本定义为:home.aspx 页面:
function ShowCurrentTime() {
var post = ({
method: "POST",
url: "home.aspx/GetData",
dataType: 'json',
data: { name: "Mobile" },
headers: { "Content-Type": "application/json" },
success: function (data) {
alert("here" + data.d.toString());
alert(data.d);
},
failure: function() {
alert("Fail");
}
});
}
第二步:
从按钮调用脚本函数:它在home.aspx页面上:
<input id="btnGetTime" type="button" value="Show Current Time" onclick="ShowCurrentTime()" />
第三步:
在home.aspx.cs页面定义的Web方法:
[System.Web.Services.WebMethod]
public static string GetData(string name)
{
return "Welcome";
}
我得到:
JavaScript 运行时错误:无法获取未定义的属性“d”或 空引用
【问题讨论】:
-
如果你能包括哪个语句引发错误会更好
-
alert("这里" + data.d.toString());此行负责错误。
-
你有什么
<head>标签?您是否包含了适合您需要的 jQuery 库?
标签: c# asp.net ajax web-services webmethod