這件事情是我的命了兩天
我有這個簡單的代碼:AJAX剛工作第一次頁面加載
<?php if(!isset($_GET['headerload'])){?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://royta.ir/js/all.js" type="text/javascript"></script>
<script src="http://royta.ir/js/main.js'?>"></script>
<div id="content">
<? } ?>
<a class="item ajax" base="basic" data-title="تنظیمات عمومی" href="http://royta.ir/general/" data-url="/general/" title="تنظیمات عمومی" >asdasd</a>
與這個jQuery
$(function() {
$('a.ajax').click(function(eee){
eee.preventDefault();
var location = $(this).attr('href') + '&headerload';
var base = $(this).attr('base');
var id = $(this).attr('data-id');
var titlepage = $(this).attr('data-title');
var url = $(this).attr('data-url');
$('#content').html('');
$('#content').empty();
//change title
$.ajax({url:location,success:function(loaddataa){
document.title = titlepage;
window.history.pushState(null, titlepage, url);
$('#content').html(loaddataa);
}
});
});
}) 但當我運行這個頁面http://royta.ir/general,你可以看到
其強制t運行1次與AJAX和一切正常,但如果你再次點擊鏈接頁面將重新加載
任何人都知道爲什麼?
在加載main.js文件結束後像魅力! –