我有个问题。我不懂JavaScript或jQuery;仅HTML,CSS,PHP和设计。我需要一个简单的jQuery函数,但我不知道该怎么做。

我需要致电以下Web服务:


http://vkontakte.ru/share.php?act=count&url=http://viberieto.ru/


此函数返回')'附近的数字。我需要在<div id="count">中显示此数字。

我怎么做?你能帮助我吗?

最佳答案

由于跨域策略的限制,您可能需要通过jsonp获取数据。
幸运的是,使用jQuery很容易做到这一点。

$.getScript("http://vkontakte.ru/share.php?act=count&url=http://viberieto.ru/");


这将创建一个新的脚本标签,其中包含Web服务返回的代码。要处理响应,您需要创建一个类似url中的对象结构:

var VK = {
  Share: {
    count: function(arg1, arg2) {
      // Insert the value into the div
      $('#count').html(arg2);
    }
  }
};
VK


编辑:固定错别字

关于javascript - javascript或jquery简单代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5411615/

10-14 14:22
查看更多