如何重装一个div无需重新加载整个页面? [英] How to reload a div without reloading the entire page?
问题描述
我想什么,我问的是对你最真的很容易。我想重装一个div没有重新加载整个页面。什么是做到这一点的最好方法是什么?
I suppose what I am asking is really easy for most of you. I want to reload a div without reloading the entire page. What's the best way to do it?
<div class="black_text" id="cp_in_content_div">
<?php
$id = $_GET["id"];
$result = mysql_query("SELECT * FROM Setting WHERE ID = $id");
$row = mysql_fetch_array($result);
switch ($_GET["action"])
{
case "delete":
if (!unlink("$_SERVER[DOCUMENT_ROOT]setting/$row[Filename]"))
{
echo "Error.";
header("Refresh: 2.5; URL=delete_setting.php?id=$id");
exit();
}
if (!mysql_query("DELETE FROM Setting WHERE ID = $id"))
{
echo "Error.";
header("Refresh: 2.5; URL=delete_setting.php?id=$id");
exit();
}
else
{
echo "Ok!";
header("Refresh: 1.25; URL=index.php");
}
break;
default:
echo "form";
}
?>
</div>
我需要那些标题(刷新:...),只刷新页面的DIV,而不是
I need those header("Refresh:...") to only reload the div instead of the page.
推荐答案
jQuery.load()可能是最简单的方法异步使用选择,但你也可以使用任何的jQuery的AJAX方法来加载数据(GET,POST,的getJSON,AJAX,等等。)
jQuery.load() is probably the easiest way to load data asynchronously using a selector, but you can also use any of the jquery ajax methods (get, post, getJSON, ajax, etc.)
请注意,负载允许你使用一个选择器来指定哪块要载入,在加载脚本
Note that load allows you to use a selector to specify what piece of the loaded script you want to load, as in
$("#mydiv").load(location.href + " #mydiv");
请注意,这在技术上不加载整个页面和jQuery去除一切,但你选择,但是这一切都在内部完成。
Note that this technically does load the whole page and jquery removes everything but what you have selected, but that's all done internally.
这篇关于如何重装一个div无需重新加载整个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!