ASP.net PageMethods返回undefined [英] ASP.net PageMethods return undefined
本文介绍了ASP.net PageMethods返回undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我试图从CS数据使用ToolkitScriptManager到js的。
这是我的aspx:
Hi everyone i trying to get data from cs to js using ToolkitScriptManager. this is my aspx :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../assets/lib/jquery/jquery-2.0.3.js" type="text/javascript"></script>
<script>
$(window).load(function () {
alert(PageMethods.isConnected());
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager runat="Server"
EnablePageMethods="true"
EnablePartialRendering="true" />
<div>
</div>
</form>
</body>
</html>
这背后
[ScriptMethod, WebMethod]
public static bool isConnected()
{
return true;
}
我不知道,但这个结果保持不确定的,对不起,如果这是真的对你简单的问题,但对我这么辛苦,因为我在asp.net新
请帮我解决这个问题。
i dont know, but this keep result undefined, sorry if this is really simple problem for you, but for me so hard, because i am new in asp.net please help me to fix this problem.
推荐答案
您需要提供的的成功和失败的回调以WebMethod的调用如下。
You need to supply a success and a failure callback to the webmethod call as below.
$(window).load(function () {
PageMethods.isConnected(fnsuccesscallback,fnerrorcallback);
});
function fnsuccesscallback(data) {
alert(data);
}
function fnerrorcallback(result) {
alert(result.statusText);
}
此外,有访问用$就页面的方法的另一种方式。
Also, there is another way of accessing the page methods using $.ajax.
<head id="Head1" runat="server">
<title></title>
<script src="../assets/lib/jquery/jquery-2.0.3.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(window).load(function () {
$.ajax({
type: "POST",
url: "PageMethodTest.aspx/isConnected",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: fnsuccesscallback,
error:fnerrorcallback
});
}); function fnsuccesscallback(data) {
alert(data.d);
}
function fnerrorcallback(result) {
alert(result.statusText);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager EnablePageMethods="true" runat="server">
</asp:ScriptManager>
<div>
</div>
</form>
</body>
这篇关于ASP.net PageMethods返回undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文