ASP.NET PageMethod 失败。怎么知道为什么呢?
当我尝试在 javascript 代码中访问 PageMethod 时,它总是不成功。我在 onfailed 方法中使用 get_message() 但没有显示相关信息。我想知道真正的问题是什么。 我有一个带有两个按钮的 jquery 弹出窗口。当按下 Guardar 按钮时,我需要执行页面方法“GuardaCommentario”(SaveComment)。这是我的代码:
$(document).ready(function () {
// Dialogo
$('#dialog').dialog({
autoOpen: false,
resizable: false,
modal: true,
width: 450,
buttons: {
"Guardar": function () {
$(this).dialog("close");
// Llamada ajax para guardar el comentario
PageMethods.GuardaComentario(onSucceed, onFailed);
},
"Cancelar": function () {
$(this).dialog("close");
}
}
});
// Dialogo Link
$('#dialog_link').click(function () {
$('#dialog').dialog('open');
return false;
});
});
function onSucceed(res, destCtrl) { alert("OK"); }
function onFailed(res, destCtrl) { alert(res.get_message()); }
谢谢你!!
When I try to access a PageMethod within javascript code it always is unsuccessfull. I use get_message() in onfailed method but no relevant informations is displayed. I'd like to get what's the actual problem.
I have a jquery popup with two buttons. When Guardar button is pressed I need that the pagemethod "GuardaComentario" (SaveComment) is executed. This is my code:
$(document).ready(function () {
// Dialogo
$('#dialog').dialog({
autoOpen: false,
resizable: false,
modal: true,
width: 450,
buttons: {
"Guardar": function () {
$(this).dialog("close");
// Llamada ajax para guardar el comentario
PageMethods.GuardaComentario(onSucceed, onFailed);
},
"Cancelar": function () {
$(this).dialog("close");
}
}
});
// Dialogo Link
$('#dialog_link').click(function () {
$('#dialog').dialog('open');
return false;
});
});
function onSucceed(res, destCtrl) { alert("OK"); }
function onFailed(res, destCtrl) { alert(res.get_message()); }
Thank you!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
失败的原因可能是任何原因 - 例如,未生成 PageMethods 的 java 脚本代理、配置文件存在问题以及 PageMethod 调用未正确路由等。您必须一一调查它们。是否有任何java脚本错误 - 检查FireFox中的FireBug等工具(其他浏览器有类似的工具)来检查脚本问题。如果没有脚本问题,那么您应该检查请求/响应 - 使用 Fiddler(或 Firebug)等工具查看向服务器发出的请求以及服务器对其的响应。最后,您可以调试应用程序并在 PageMethod 代码中放置一个断点,以查看请求是否到达那里。
Reasons for failure can be anything - for example, java-script proxies for PageMethods are not generated, there are issue in configuration files and there fore PageMethod calls are not routed correctly etc. You have to investigate them one by one. Are there any java-script errors - check tools such as FireBug in FireFox (other browsers have similar tools) to check for script issue. If there are no script issue then you should inspect request/response - use tool such Fiddler (or Firebug) see what request being fired to server and server's response to it. Lastly, you can debug your app and put a break-point in your PageMethod code to see if request reaches to there.