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

  • SEARCH
  • Home
  • 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 6992477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:38:21+00:00 2026-05-27T19:38:21+00:00

I am working on a script which will fetch the latest tweets from the

  • 0

I am working on a script which will “fetch” the latest tweets from the Twitter API, and then display them as HTML on my page using JQuery.

I’m new to JQuery, so if someone could point me in the direction of the necessary function on the JQuery site I would be most grateful.

I currently have built the following script:

<!-- Use the Google jQuery CDN for lib support -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- Setup and fetch the JSON data -->
<script type="text/javascript">
$(document).ready(function(){
var url='http://search.twitter.com/search.json?callback=?&q=@req';
$.getJSON(url,function(json){
<!-- Iterate the file -->
        $.each(json.results,function(i,tweet){
           $("#results").append('<p><img src="'+tweet.profile_image_url+'" widt="48" height="48" />'+tweet.text+'</p>');
$("#results").slideDown("slow");
        });
                    });
});
</script>
<!-- Output the file into the DIV -->
<div id="results"></div>

The script is working fine, however I would now like to incorporate some form of automatic refresh of the content. I.e “re-fetch” the feed every x minutes.

From what I understand I need to replace .append with .html in order that the content is removed from the page before reload, however does anyone have any suggestions as to the best way of actually getting the content to refresh? I have found may articles expressing concerns over browser memory leaks etc, and don’t want to head down the wrong path.

I look forward to you responses, and thanks again.

  • 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-27T19:38:22+00:00Added an answer on May 27, 2026 at 7:38 pm
    $(function(){
        function getTweets() {
            var url='http://search.twitter.com/search.json?callback=?&q=@req';
            $.getJSON(url,function(json){
    
                //setup an array to buffer output
                var output = [];
    
                //a for loop will perform faster when setup like this
                for (var i = 0, len = json.results.length; i < len; i++) {
    
                   //instead of appending each result, add each to the buffer array
                   output.push('<p><img src="' + json.results[i].profile_image_url + '" widt="48" height="48" />' + json.results[i].text + '</p>');
                }
    
                //now select the #results element only once and append all the output at once, then slide it into view
                $("#results").html(output.join('')).slideDown('slow');
            });
        }
    
        //set an interval to run the getTweets function (30,000 ms is 5 minutes), you can cancel the interval by calling clearInterval(timer);
        var timer = setInterval(getTweets, 30000);
    
        //run the getTweets function on document.ready
        getTweets();
    
    });
    

    Here is some good documentation for window.setInterval(): https://developer.mozilla.org/en/window.setInterval

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

Sidebar

Related Questions

I'm working with a script in which the postid of the page has been
I am working to create a script which will take a string as an
I'm working on a Perl script which is called from a server side include
I'm currently working on a reminder PHP Script which will be called via Cronjob
i am working on unix. i want to write a shell script which will
I have developed the following user script which will show the html element under
I'm working on a script which will go along with my already in place
I'm working on a script which will get a JSON array of id's. Based
I am building a python script which will be removing duplicates from my library
Can a PHP script (which can be working with a MySQL DB) send and/or

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.