简体   繁体   中英

how i can set this src value using jQuery or javascript

var fileref = document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", "http://search.twitter.com/search.json?
                            q="+buildString+"&callback=TweetTick&rpp=50");
document.getElementsByTagName("head")[0].appendChild(fileref);

Here buildString value is

from:@one+OR+from:null+OR+from:@two+OR+from:null+OR+from:@three+OR+
from:null+OR+from:null+OR+from:@four+OR+from:null+OR+from:@five+OR+
from:null+OR+from:@six+OR+from:null+OR+from:@seven+OR+from:null+OR+
from:@eight

Here when i used buildString value( ie what i specified ) to set the value for src it is working properly for me.

But if i set buildString directly it is giving exception for me.

  SyntaxError: illegal character

TweetTick(�

If my question is not clear i will explain more detail.

Please help me.Thanks in advance..

Try this -

var source = "http://search.twitter.com/search.json?q="+buildString+"&callback=TweetTick&rpp=50";
fileref.setAttribute("src",encodeURI(source));

Seems like API v1 search has stopped working, you should upgrade to API v1.1 which now require authentificated user. Even direct link to API search seems still to work, i can no more access it using ajax json request.

See (not clear) annoucement here: https://dev.twitter.com/blog/planning-for-api-v1-retirement

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM