jQuery Mobile“加载页面时出错”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12910813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Mobile “Error Loading Page”
提问by Srikanth Chilukuri
I am using Jquery1.8.2 and Jquery-mobile 1.1
我正在使用 Jquery1.8.2 和 Jquery-mobile 1.1
When i click on Logout button i have to goto the Home page. I am able get the home page but before going back to the home page got the "Error Loading Page"message.
当我点击注销按钮时,我必须转到主页。我能够获得主页,但在返回主页之前收到“错误加载页面”消息。
Test.html
测试.html
<body>
<div data-role="page">
<div data-role="header" data-theme="b" >
<h1> Success Page </h1>
<a data-role="button" id="logoutbtn" data-theme="b">Logout</a>
</div><!-- /header -->
<div data-role='content'>
</div>
</div>
</body>
test.js
测试.js
$(document).ready(function(){
$("#logoutbtn").click(function () {
document.location.href = "Home.html";
});
});
Please help me out on this.
请帮我解决这个问题。
采纳答案by Srikanth Chilukuri
Thanks Dipaks
谢谢迪帕克斯
Instead of
代替
document.location.href = "/Home.html";
I have modified it as like below
我已经修改如下
document.location.href = "./Home.html";
Its working fine and able to go back to home page with out any error.
它工作正常并且能够返回主页而没有任何错误。
回答by andleer
You should be using the jquery mobile specific methods.
您应该使用 jquery mobile 特定的方法。
$.mobile.changePage("Home.html");
See document-location-href-location-vs-mobile-changepagelocation
回答by user2114127
$.mobile.changePage("Home.html")
did not work on my PC
$.mobile.changePage("Home.html")
不能在我的电脑上工作
but instead $.mobile.changePage("#");
works and it's hiding the error loading page
message.
而是$.mobile.changePage("#");
有效并且它隐藏了error loading page
消息。
回答by Mustafa
I was using the right versions and $.mobile.changePage to change a page and it still failed with the same error. Later I realized that I was doing this in a js file in www/js/custom/handler/handler.js. So I was using paths relative to this location.
我使用正确的版本和 $.mobile.changePage 来更改页面,但它仍然因相同的错误而失败。后来我意识到我是在 www/js/custom/handler/handler.js 中的一个 js 文件中这样做的。所以我使用的是相对于这个位置的路径。
However later I realized that the path has to be relative to index.html that includes this js.
但是后来我意识到路径必须相对于包含此 js 的 index.html。
That resolved my issue.
那解决了我的问题。