Skip to content Skip to sidebar Skip to footer

Cronjob But For JQuery/Javascript

I'm trying to develop a web application that mainly uses PHP but i'm using jQuery/Javascript to grab people's Tweets from their URL: http://twitter.com/status/user_timeline/joeblog

Solution 1:

The javascript method setInterval allows you to pass a method and a number of milliseconds. The method you provide will be executed every number of milliseconds you provided. So if you wanted to grab the latest tweets every 30 seconds, you would call something like this:

setInterval(updateTweets,30000);

This would call the method updateTweets every thirty seconds, where you could use ajax to load up the latest tweets.

For more information on setInterval, you can check out: http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/


Solution 2:

The best solution is to re-implement your functionality in PHP:

<?    
$url = "http://twitter.com/status/user_timeline/joebloggs.json?count=1&callback=?";
$responseJsonString = file_get_contents($url);
$responseArray = json_decode($responseJsonString, $array=true);

// uncomment this to see what's in the response array:
// print_r($responseArray);
// Now, you can do as you like with $responseArray

And then execute the PHP script via crontab.


Post a Comment for "Cronjob But For JQuery/Javascript"