【发布时间】:2016-04-01 07:22:41
【问题描述】:
我是新手,所以我会尽量清楚, 我正在尝试使用 Jquery 和 AJAX 创建一个单页应用程序。但是,什么都没有发生,没有错误,什么都没有。
转到 main、second 和third 是指向:#/main、#/second、#/third
另外,first.html、second.html、third.html 是应该从中检索数据的页面。
请检查我的代码,如果有问题请告诉我:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
window.addEventListener('hashchange', function (){
if(window.location.haschange === '#/main'){
$.get( "first.html", function( data ) {
$( "#examples" ).html( data );
})
}
if(window.location.haschange === '#/second'){
$.get( "second.html", function( data ) {
$( "#examples" ).html( data );
})
}
if(window.location.haschange === '#/third'){
$.get( "third.html", function( data ) {
$( "#examples" ).html( data );
})
}
});
</script>
<## Heading ##html>
<head>
<title>text</title>
</head>
<body>
<ul>
<li><button><a href="#/main">Go to Main</button></li>
<li><button><a href="#/second">Go to Second</button></li>
<li><button><a href="#/third">Go to Third</button></li>
</ul>
<div id="examples">
</div>
</body>
</html>
<!-- begin snippet: js hide: false -->
【问题讨论】:
-
window.addEventListener('hashchange',。我认为您在这里有一个很大的旧错字。 -
我不太确定
hasChanged是否存在。
标签: javascript jquery html json ajax