我正在使用 jQuery 和 PHP,我对history.pushState
.
当我单击锚标记或链接时,一旦浏览器中的 URL 看起来像这样www.example.com/index.php/home/viewer/id
当我再次单击该链接时,浏览器中的 URL 看起来像这样
www.example.com/index.php/home/photo_viewer/index.php/home/viewer/id
,这是不正确的。
我希望浏览器中的 URL 是www.example.com/index.php/home/viewer/id
我该如何解决这个问题?
<a href="index.php/home/viewer/ $row['id'] " Onclick="viewer(this); return false;"> id </a>
<script type="text/javascript">
function viewer(link){
var ajax_data ={ajax:'1'};
$.ajax({
type: "POST",
url: link,
data: ajax_data,
success: function(html){
$("#viewer").html(html);
window.history.pushState(null,null, link);
e.preventDefault();
}});
return false; }