开发者

Redirect a page and load/refresh a div within that page using ajax

开发者 https://www.devze.com 2023-03-10 12:22 出处:网络
I am using ajax to redirect to a page by window.location = \"page.php\" After the page is redirected I need to load a div within that page. For example search.php.

I am using ajax to redirect to a page by window.location = "page.php"

After the page is redirected I need to load a div within that page. For example search.php.

I have been reading up on how to do this and from what I gather you can do this by using jquery. I have never used jquery so if someone can help me out I will really appreciate it.

If it can be done without jquery even better!

Edit: Let me explain again what I am trying to do. I have a table that updates that the db. All of it is done through php, js and ajax.

For example "Displaytable.php" displays the 开发者_高级运维table. The user can search and it replaces the search result in a div. When someone wants to update it goes to update.php. After it's updated i want to redirect the page to Displaytable.php with the search results in the div. I am using session variables to do the search. The search works fine i have tested it in another page.


May be this is what you are looking for (using jQuery):

In page.php:

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

Description:
This will load the page search.php into the (div) element with id, "divID" after page.php has been loaded.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号