jQuery将div添加到另一个页面

时间:2012-08-04 15:22:34

标签: php jquery html panel add

我正在做一个小管理面板,并想知道是否可以在单击面板中的按钮后使用jQuery在index.php文件中添加div框?

如果是这样的话,可以赞赏一个小例子!

2 个答案:

答案 0 :(得分:0)

您需要使用jQuery的$.post()方法发送XML http post请求,然后在服务器上有一个php文件修改索引文件,或者可以包含在索引文件中的文本文件:< / p>

$.post('indexEdit.php', {info: "info to ad to file"}, function(data){ /*callback here*/ });

确保indexEdit.php具有会话验证或其他人可以尝试向其发布信息并执行外部编辑。

答案 1 :(得分:0)

要将代码添加到div的开头,请使用prepend方法。要将代码添加到div的末尾,请使用append方法。

以下是将代码添加到html页面正文的2个示例:

$("body").prepend("This is some div added to the start of the page.");
$("body").append("This is some div added to the end of the page.");

如果您想动态加载内容,则必须使用ajax方法并在回调中使用上述代码。