首先,
$("document")
應該
$(document)
因爲沒有<document>
元素,如果有的話,你就不會被要求他們.ready()
。
接下來,您看到此問題的原因是因爲$(document).ready()
僅在每個整頁加載時觸發一次。在jQuery Mobile中更改爲新頁面不會觸發整頁加載,而是會使用ajax加載到新頁面中。 。爲了解決這個問題,jQuery Mobile的有一個稱爲是獲取獲取加載頁面上引發「pageinit」的事件這是你會怎麼給它綁定在你的情況:
前的jQuery 1.7
// yes, i know delegate is better, but the documentation specifically suggested using .live
$("#pageid").live("pageinit",function(){
$.ajax({
url: 'data.php',
success: function(data) {
$("#result").html(data).trigger('create');
$("#result").listview('refresh');
}
});
});
後的jQuery 1.7
$(document).on("pageinit","#pageid",function(){
$.ajax({
url: 'data.php',
success: function(data) {
$("#result").html(data).trigger('create');
$("#result").listview('refresh');
}
});
});
原因刷新頁面的工作原理是,因爲當你刷新頁面,則$(document).ready()
事件發生。
jQuery的'.ajax()'函數_is_正在執行XMLHttpRequest調用。您是否嘗試過使用控制檯進行調試? – j08691
不要在jQuery Mobile中使用document.ready。你需要的是'$(document).on(「pageinit」,「#pageid」,function(){/ *在這裏做ajax * /});' –
@KevinB - 我錯過了jQuery移動提及的地方? – j08691