Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1101005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:58:14+00:00 2026-05-17T00:58:14+00:00

This has been driving me nuts for a few days. I am desperate for

  • 0

This has been driving me nuts for a few days. I am desperate for help.

I have 2 files, index.php and test.php, simplied version to follow.

index.php

<div id="div-hi"></div>
<div id="div-bye"></div>

<script>
$(document).ready(function(){ setInterval(function(){
$( function() 
{
$.ajax( 
{
url : 'test.php',
type : 'post',
success : function( resp ) 
    {
    $('#div-hi').html(resp);
    $('#div-bye').html(resp);
    }
});return false;}
);}, 1000);});  
</script>

test.php

<div id="hi">
<script type="text/javascript">
---
</script>
</div>

<div id="bye">
<script type="text/javascript">
----
</script>
</div>

I want #div-hi in index.php to contain the result of my javascript from #hi from test.php and #div-bye from index.php to contain the result from #bye from test.php.

I have ran out of ideas. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:58:14+00:00Added an answer on May 17, 2026 at 12:58 am

    Your Javascript:

    You’ve got a few extra brackets and parens, and I don’t know what the return false is doing in this case…

    The format for setInterval() is

    setInterval( CODE, DELAY);
    

    using an anonymous function with $.ajax() that’s:

    setInterval( function() { $.ajax( ... ) }, 1000);
    

    Also, return false is usually used to cancel defualt behavior in jQuery…. it doesn’t apply here.

    If your response is HTML, you can extract a div from it with find() or a context.

    Try something like this:

    <div id="div-hi"></div>
    <div id="div-bye"></div>
    
    <script type="text/javascript">
    $(document).ready(function() { 
        setInterval(function() {
            $.ajax( 
            {
                url : 'test.php',
                type : 'post',
                success : function( resp ) 
                {
                      // Find the #hi and #bye divs in resp
                      //   and display them in #div-hi and #div-bye
                    $('#div-hi').html($("#hi", resp).html());
                    $('#div-bye').html($("#bye", resp).html());
                }
            });       
        } , 1000);
    });  
    </script>
    

    Working jsFiddle

    ( note how the {}s appear after a few secs )


    Extracting DIVs from a page:

    Use the .load() function if you simply want to load pieces of another page onto the current page.

    For example if you’re on index.php and you want to grab the contents of #hi and #bye from test.php and display them in #div-hi and #div-bye

    $('#div-hi').load('test.php #hi');
    $('#div-bye').load('test.php #bye');
    

    The above is two calls though, but I just wanted to illustrate the use of .load().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one has been driving me nuts for a few days now and I've
This has been driving me nuts for the last 2 days. I have 3
This has been driving me crazy for a few days. Why doesn't the following
This has been driving me crazy for the past few minutes I have a
This has been driving me nuts for a week now. I have a class
This has been driving me nuts all day. I have a weird bug that
This error has been driving me nuts. We have a server running Apache and
This has been driving me absolutely nuts. I have a substitute function like this:
This one has been driving me nuts. I have a div that has it's
This has been driving me mad for a few days... Create a new Window-based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.