나는 onpopstate로 놀기 시작했으나 문제가 발생했습니다. 내 브라우저에서 뒤로 버튼을 클릭 할 때마다 URL이 적절하게 변경되지만 페이지 코드가 두 번로드되어 두 개의 목록과 두 개의 div가 수신됩니다. 코드를 두 번 생성하는 이유는 무엇이며 어떻게 수정합니까? 샘플 코드는 아래와 같습니다.데이터를 두 번 반환하는 onpopstate
<style type="text/css">
div {width: 200px; height: 200px; border: 1px solid;}
</style>
<ul>
<li class="sour">
<input type="button" value="1"/>
</li>
</ul>
<script type="text/javascript" >
$('ul li:nth-child(1)').click(function() {
var url = $(this).index();
$('#insert').load('1.php');
window.history.pushState('', '', 'test1.php?challenge=' + url);
e.preventDefault();
});
window.onpopstate = function(event) {
$('#insert').load(location.pathname);
};
</script>
<div id="insert">
<p>hello there</p>
</div>
여기 여기에 시각적으로 무슨 일 찍은 스크린 샷에 대한 링크가 1.php
<p>first file</p>
의 내용입니다. 첫 번째 이미지는 처음 화면을로드 할 때의 이미지입니다. 두 번째 이미지는 버튼 1을 누르면 발생합니다. 세 번째 이미지는 브라우저에서 다시 클릭하면 발생합니다.
http://imgur.com/Nsqej,E1Ydc,sFCLl#0
pjax가 작동하는 것으로 밝혀졌습니다. 감사. – jason328