作者henry4343 (henry)
看板Ajax
標題[問題] history.putState & Ajax 問題
時間Tue Jul 23 14:49:37 2013
請問一下各位
我想要使用Ajax更新ol的資料 又想要達到回上一頁的功能
看了一下網路的範例
http://stackoverflow.com/questions/10571734/html5-history-api-demo
這個範例可以達到我想要的功能
不過我要使用jQuery的ajax從php撈資料
我改寫了一下code以後變成
document.getElementById ('menu').addEventListener('click',function(event){
var el = event.targe;
event.preventDefault ();
if (el.nodeName === 'A') {
// Gets url of the page
var sourcePath = el.getAttribute ('href');
$.post("fileQuery.php",
{
filePath:sourcePath
},
function(data,status){
history.pushState (data, null, el.href);
update(data);
});
}
});
當我第一次點到li的時候有正確撈回資料並顯示出來,回上一頁的按鈕也可以按
不過上一頁的按鈕按了沒有反應
然後當我第二次以後點li的時候 ajax就一直沒辦法傳回資料(function無反應),不過
當我把history.pustState那一行註解掉以後,就可以正常使用(不過這樣就沒有上一頁
的功能了)
希望有經驗的大大可以幫幫忙
謝謝~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 124.11.17.212
1F:→ alpe:你用那個瀏覽器 07/23 15:53
2F:→ henry4343:chrome 07/23 16:57
3F:→ henry4343:我改成用$.ajax就可以了.... 真怪 07/23 16:57