从ajax提取数据后重新加载页面
我使用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刷新页面后,就会消失的数据。
保存在session
或database
,然后数据从那里取 因为清爽页面get
和post
变量后自动销毁。
是否有任何其他选项insted会话和存储在数据库中??? –
是的,当你得到的内容,然后再次张贴在同一页上的价值一次又一次 –
考虑使用cookie数据。
这个jQuery插件将这样的伎俩: http://plugins.jquery.com/project/cookie
$.cookie('example', 'foo'); //the name is example and that value is foo.
获取cookie的值是简单...
alert($.cookie('example');
加载数据,以便动态地后,你既可以存储数据在一个cookie中。尽管如果您获取大量数据,这可能是一个不好的解决方案。
这个问题很难回答,因为缺乏示例代码,因此不能理解你的意图或你如何/做什么。
您应该向社区提供一些您的代码,以便我们可以看到您要做的事情并为您提供详细的帮助。 – sirmdawg
假设有一个div的id为demoDiv,并且来自搜索页面的响应数据出现在这个div中,现在当我刷新页面时,这个div数据将消失...但我希望在重新加载页面后数据将保留在此处。 。这对你来说是可以理解的,现在我的问题是什么? –
是的,你可以编辑你的问题,包括你使用的示例代码?也许阿贾克斯加载部分? – sirmdawg