当前位置:编程学习 > C#/ASP.NET >>

不能获取外域json数据

 $.ajax({
            type: "POST",
            url: "http://www.weather.com.cn/data/sk/101010100.html",
            data: {},
            dataType: "json",
            async: false,
            success: function (rest) {
                var datr = rest.weatherinfo;
                alert(datr);
            }

        })

在网上找了一个天气预报的接口,alert是空,求解··· json asp.net  --------------------编程问答-------------------- 跨域正常的方法是获得不到的,

看看下链接的Case III. iframe方式 (on Server A)
http://www.cnblogs.com/guowei1027/archive/2009/12/15/1625170.html --------------------编程问答-------------------- 你可以在后台通过构造http访问来获取对象后提交给前台显示(ajaxpro这个东西可以让前台js执行后台的代码) --------------------编程问答-------------------- 跨域你就不能那么post了。  得用jsonp --------------------编程问答-------------------- type: "GET"
可能出现这个错误,参照:
http://blog.csdn.net/meditatorzhang/article/details/7612458 --------------------编程问答--------------------
引用 3 楼 yumen3501 的回复:
跨域你就不能那么post了。  得用jsonp

这个试过也不行。有木有具体例子 --------------------编程问答--------------------

<script type="text/javascript">  
    $.ajax({  
        url:"http://xxx.com/xxx.xxx",  
        dataType:'jsonp',  
        data:'',  
        jsonp:'callback',  
        success:function(result) {  

        },  
        timeout:3000  
    });  
</script>  


引用 5 楼 foreveryimada 的回复:
引用 3 楼 yumen3501 的回复:跨域你就不能那么post了。  得用jsonp
这个试过也不行。有木有具体例子
--------------------编程问答-------------------- jsonp只直接get,而且需要服务端支持
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,