Search code examples
phpjqueryajaxhttp-redirectpartial-page-refresh

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


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.


Solution

  • 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.