0

我正在使用 ajax 通过 window.location = "page.php" 重定向到页面

页面重定向后,我需要在该页面中加载一个 div。例如 search.php。

我一直在阅读有关如何执行此操作的信息,并且从我收集到的内容中,您可以使用jquery来执行此操作。我从未使用过jquery,所以如果有人可以帮助我,我将非常感激。

如果它可以在没有jquery的情况下完成就更好了!

编辑:让我再次解释一下我想要做什么。我有一张表可以更新该数据库。所有这些都是通过 php、js 和 ajax 完成的。

例如“Displaytable.php”显示表格。用户可以搜索,它将搜索结果替换为 div。当有人想要更新它时,它会转到 update.php。更新后,我想将页面重定向到 Displaytable.php,并在 div 中搜索结果。我正在使用会话变量进行搜索。搜索工作正常,我已经在另一个页面中对其进行了测试。

4

2 回答 2

0

jQuery is written in JavaScript, so you can always do without jQuery if you write it yourself--a matter of brevity though.

Seems you are trying to continue controlling the window after you have loaded another page into it. You can't do this if you are changing the current window's location (though, if the page in question is in the same domain (e.g., if both pages are on www.example.com). (You can if you are opening another window or adding a page within the current page.)

If the redirected page is under your control, you can load a div asynchronously (look for a tutorial on Ajax--though jQuery does offer a convenient, well-tested, cross-browser approach which may be more cumbersome on your own) by adding an onload event in the opened page and populating the div at that point.

于 2011-06-03T19:15:29.117 回答
0

可能这就是您正在寻找的(使用 jQuery):

page.php

<script>
//<![CDATA[
$(function() {
    $("#divID").load('search.php');
});
//]]</script>

描述:
这会将页面加载search.php到具有 id 的 ( div) 元素中,"divID"page.php加载后。

于 2011-06-03T19:23:08.593 回答