admin管理员组文章数量:1336660
I want use ajax on ASP.NET platform. For that I use ScriptManager. Simply I add this script with jQuery after when "document is ready".
$(document).ready(function () {
// sync
{{scopeName}}_init();
// async
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function (sender, args) {
{{scopeName}}_init();
});
});
And then such a mysterious javascript error happened.
Uncaught ReferenceError: Sys is not defined
Q what I have wrong if javascript stop working after first request?
I want use ajax on ASP.NET platform. For that I use ScriptManager. Simply I add this script with jQuery after when "document is ready".
$(document).ready(function () {
// sync
{{scopeName}}_init();
// async
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function (sender, args) {
{{scopeName}}_init();
});
});
And then such a mysterious javascript error happened.
Uncaught ReferenceError: Sys is not defined
Q what I have wrong if javascript stop working after first request?
Share Improve this question asked Feb 23, 2016 at 20:11 BrunoBruno 7,2215 gold badges44 silver badges49 bronze badges2 Answers
Reset to default 1Solution is not skip "Sys.WebForms.PageRequestManager" using undefined condition
if (typeof(Sys) !== 'undefined') {
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function (sender, args) {
{{scopeName}}_init();
});
}
For the postback we init function just if document is ready - sync section.
For ajax request in ScriptManager block we need to register init function on "add_pageLoaded". After that everytime script works fine at first request - async section.
Most important neglected step is register also "add_endRequest", and that fix the problem.
Whole example code:
$(document).ready(function () {
// sync
console.log("sync");
{{scopeName}}_init();
// async
pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
pageRequestManager.add_endRequest({{scopeName}}_onAsyncEndRequest);
pageRequestManager.add_pageLoaded({{scopeName}}_onAsyncPageLoaded);
});
function {{scopeName}}_onAsyncEndRequest(sender, args) {
console.log("async end");
console.log(args);
}
function {{scopeName}}_onAsyncPageLoaded(sender, args) {
console.log("async start");
{{scopeName}}_init();
}
I recently ran across this problem myself so I figured I would type this up to help someone who might be going through the same/similar issue.
What I found out was that when VS deployed the application, and I started running the app on my production server, my browser was looking for ScriptResource.axd
(for ASP.NET AJAX) and WebResource.axd
, and not finding either file in the root directory.
More on these files: What is WebResource.axd?
本文标签: javascriptUncaught ReferenceError Sys is not defined on ASPNETStack Overflow
版权声明:本文标题:javascript - Uncaught ReferenceError: Sys is not defined on ASP.NET - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742418050a2471101.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论