问题与jQuery JSONP Twitter的搜索请求 [英] Problem with jQuery JSONP twitter search request

查看:173
本文介绍了问题与jQuery JSONP Twitter的搜索请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些困难,使用JSONP search.json正确检索Twitter数据。

I'm having some difficulties to correctly retrieve Twitter data using jsonp search.json.

当我取数据只有一次,它完美的作品与这片code的:

function getTweets(){
    $.ajax({
       url: 'http://search.twitter.com/search.json',
       type: 'GET',
       dataType: 'jsonp',
       jsonpCallback: 'tw_callback',
       data: 'q=<?php echo urlencode($twitter_search); ?>+-RT&rpp=100'
    });
}

function tw_callback(jsonp){
    for( key in jsonp['results'] ) {    
        var tweet = jsonp['results'][key]['text'] ;
        var from = jsonp['results'][key]['from_user'];
        var avatar = jsonp['results'][key]['profile_image_url'];

        tw_container.push([tweet,from,avatar]);
    }
}

但是当我尝试再刷新该数据每xx秒,使用的setInterval:

setInterval(function () { getTweets(); }, 1000*interval_tourniquet);

不幸的是它不工作。我有这个错误:

It unfortunately doesn't work. I'm having this error:

NOT_FOUND_ERR:DOM异常8:一个
  试图引用一个节点
  在上下文中,其中它不存在

NOT_FOUND_ERR: DOM Exception 8: An attempt was made to reference a Node in a context where it does not exist.

基本上,我得到了这样每次我试图打电话给我getTweets()功能的函数内部的时间...:(

basically, I got this every time I try to call my getTweets() function inside another function... :(

其他解决方案,我想:

function getTweets(){
    $.ajax({
        url: 'http://search.twitter.com/search.json',
        type: 'GET',
        dataType: 'jsonp',
        data: 'callback=tw_callback&q=<?php echo urlencode($twitter_search); ?>+-RT&rpp=100'
    });
}

这它的工作方式完美地与另一台服务器上我自己的JSONP的API,但Twitter返回我我的回调两次:

This way it works perfectly with my own jsonp api on another server, but Twitter returns me my callback twice:

tw_callback(tw_callback({结果...

tw_callback(tw_callback({results...

而JSONP字符串不跨preTED ..

And the jsonp string is not interpreted..

在此任何线索,任何暗示?

Any clue on this, any hint?

感谢名单了很多!

推荐答案

尝试使用以下,更简单,方式重写你的函数。

Try to rewrite your function with the following, more simple, way.

function getTweets(){
    $.ajax({
       url: 'http://search.twitter.com/search.json?q=<?php echo urlencode($twitter_search); ?>&rpp=100&callback=?',
       dataType: 'jsonp',
       success: function(){ 

            for( key in jsonp['results'] ) {    
                var tweet = jsonp['results'][key]['text'] ;
                var from = jsonp['results'][key]['from_user'];
                var avatar = jsonp['results'][key]['profile_image_url'];

                tw_container.push([tweet,from,avatar]);
            }
        }
    });
}

这篇关于问题与jQuery JSONP Twitter的搜索请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆