是否有某种方法可以汇总来自两个不同网址的两个不同推文编号?我的博客文章有多个划分的页面,用户从不同的 url 发推文(在本例中是从 Page1 或 Page2):
Example:
htttp://mydomain.com/article/page/1.html
htttp://mydomain.com/article/page/2.html
我目前正在使用 jQuery 和 Topsy 的 otter API 显示一篇文章中的推文数量。我想合并 Page1 和 Page2 的推文数量。
<script>
$(document).ready(function() {
url = "http://mydomain.com/article/page/1.html";
// Get Number of Tweet Count From Topsy
$.getJSON('http://otter.topsy.com/stats.js?url='+url+'&callback=?',
function(data) {
$('#tweet').append(data.response.all);
});
})
</script>
最佳答案
由于查询是异步的,因此需要将第二个查询嵌套在第一个查询的回调函数中
$(document).ready(function() {
url1 = "http://mydomain.com/article/page/1.html";
url2 = "http://mydomain.com/article/page/2.html";
$.getJSON('http://otter.topsy.com/stats.js?url='+url1+'&callback=?',
function(data) {
count1 = parseInt(data.response.all, 10);
$.getJSON('http://otter.topsy.com/stats.js?url='+url2+'&callback=?', function(data) {
count2=parseInt(data.response.all, 10);
$('#tweet').append(''+count1 + count2);
});
});
});
关于javascript - 如何使用 jQuery 将 2 个 URL 的推文计数加在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8697212/