【发布时间】:2011-11-29 07:17:38
【问题描述】:
我正在使用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 中的数据会在刷新页面后消失。
【问题讨论】:
-
您应该向社区提供您的一些代码,以便我们了解您正在尝试做什么并为您提供详细的帮助。
-
假设有一个 id 为 demoDiv 的 div 并且来自搜索页面的响应数据进入了这个 div,现在当我刷新页面时这个 div 数据会消失......但我希望数据会保留重新加载页面后在这里...您现在可以理解这是我的问题吗???
-
是的,您可以编辑您的问题以包含您正在使用的示例代码吗?也许是 ajax 加载部分?
-
你可以尝试使用jquery cookies 或者html5 web sql,或者直接保存到数据库中