我使用ajax動態獲取數據,但存在問題。當我刷新頁面時,獲取的數據會丟失。我想刷新頁面後數據保持不變。從ajax提取數據後重新加載頁面
想這是我的網頁:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Index Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
/* fetching data which matches the keyword*/
function Search()
{
$.post("search.php", {search_word: $('#searchInput').val()} , function(data){
if(data){
$('#results').show();
$("#results").append(data);
}
});
}
</script>
</head>
<body>
<input type="text" value="" id="searchInput"/>
<input type="button" value="Search" onclick="Search();"/>
<div id="results" style="display:none"></div>
</body>
</html>
當我上的搜索按鈕,點擊它排在結果DIV刷新頁面後,就會消失的數據。
您應該向社區提供一些您的代碼,以便我們可以看到您要做的事情併爲您提供詳細的幫助。 – sirmdawg
假設有一個div的id爲demoDiv,並且來自搜索頁面的響應數據出現在這個div中,現在當我刷新頁面時,這個div數據將消失...但我希望在重新加載頁面後數據將保留在此處。 。這對你來說是可以理解的,現在我的問題是什麼? –
是的,你可以編輯你的問題,包括你使用的示例代碼?也許阿賈克斯加載部分? – sirmdawg