0
我想使用setInterval調用dajaxice函數定期檢索twitter訂閱源,但我有問題獲取函數被多次調用。 setInterval的作品,如果我只是寫一行到控制檯,但當我嘗試調用我的dajaxice函數只會發生一次。JavaScript setInterval - 函數只調用一次
ajax.py:
@dajaxice_register
def get_home_timeline(request):
home_timeline = oauth_req(
'http://api.twitter.com/1/statuses/home_timeline.json?count=2',
settings.TWITTER_TOKEN_KEY,
settings.TWITTER_TOKEN_SECRET
)
return simplejson.dumps({'home_timeline': home_timeline })
def oauth_req(url, key, secret, http_method="GET", post_body=None, http_headers=None):
consumer = oauth.Consumer(key=settings.TWITTER_CONSUMER_KEY, secret=settings.TWITTER_CONSUMER_SECRET)token = oauth.Token(key=key, secret=secret)
client = oauth.Client(consumer, token)
resp, content = client.request(
url,
method=http_method,
# body=post_body,
# headers=http_headers,
# force_auth_header=True
)
return content
base.html文件:
var get_timeline = Dajaxice.modules.ticker.get_home_timeline(get_home_timeline_callback);
function getTweets(){
intervalId = setInterval(get_timeline, 2000);
}
感謝您的幫助,
傑森