iBr*_*an2 6 javascript api twitter jquery jsonp
我有以下代码,我无法理解它为什么不返回并在HTML正文中打印它.
var pageURL = document.URL;
var tweet = "https://cdn.api.twitter.com/1/urls/count.json?url='"+ pageURL + "'";
$.getJSON(tweet,function(json){
$('#twitterfeed').html(json.count);
});
<div id="twitterfeed"></div>
Run Code Online (Sandbox Code Playgroud)
https://cdn.api.twitter.com/1/urls/count.json?url=http://www.google.com
返回{"count":23844636,"url":"http://www.google.com/"}
以下似乎没有用,有没有人知道为什么?
dai*_*ain 10
截至2015年11月20日,没有推文计数API,所以不要打扰:https://blog.twitter.com/2015/hard-decisions-for-a-sustainable-platform
默认情况下,jQuery 发出 AJAX 请求。由于它是跨域的,并且响应中不存在 CORS HTTP 标头,因此失败。添加&回调=?请求 URL 发出 JSONP 请求
var pageURL = "http://www.google.com";
var urlParams = $.param({ "url": pageURL });
var tweet = "https://cdn.api.twitter.com/1/urls/count.json?"+urlParams;
$.ajax(tweet, { "dataType" :"jsonp" }).done(function(json){
$('#twitterfeed').text(json.count);
});
Run Code Online (Sandbox Code Playgroud)
演示
http://jsbin.com/tasaloraje/edit?html,输出
| 归档时间: |
|
| 查看次数: |
5278 次 |
| 最近记录: |