从同一个域中检索JSON数据,如何使用JSONP从asp.NET另一个域获得? [英] Retrieving Json data from same domain, how to use JsonP to get from another domain with asp.NET?

查看:362
本文介绍了从同一个域中检索JSON数据,如何使用JSONP从asp.NET另一个域获得?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code检索JSON数据:

I have the following code that retrieves Json data:

   <script type="text/javascript">
   $(document).ready(
   function(){
   $.getJSON(
     './json.txt',
     function(data){

        for(i=0; i<data.length; i++){
           var  content  = '<li>';
               content +=  data[i].fname + ' ' + data[i].lname;
               content += '</li>';

           $('ul.rubrica').append(content);
        }

     }
  );
}
);
</script>
<ul class="rubrica">
</ul>

和JSON数据:

[
   {
      "fname"     : "<a href='http://www.riccardo.it'>Piottino</a>",
      "lname"     : "Mr Potato"
   }

]

现在我已经在另一台服务器的JSON: http://www.site.com/json.txt
如何使用JSONP像以前那样得到的内容?
TNX提前

Now I have the json in another server: http://www.site.com/json.txt How can I use jsonP to get the content like I did before? Tnx in advance

- 编辑:因为我知道我必须使用服务器端语言,我怎么能与asp.net做

-- Since I see I have to use a server side language, how can I do it with asp.net?

推荐答案

详细@ 的http:// API .jquery.com / jQuery.getJSON /

示例 -

$.getJSON("http://www.site.com/json.txt?jsoncallback=?",
  function(data) {
        for(i=0; i<data.length; i++){
           var  content  = '<li>';
               content +=  data[i].fname + ' ' + data[i].lname;
               content += '</li>';

           $('ul.rubrica').append(content);
});

这篇关于从同一个域中检索JSON数据,如何使用JSONP从asp.NET另一个域获得?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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