码迷,mamicode.com
首页 > Web开发 > 详细

JSONP跨域处理实例

时间:2016-05-03 12:34:02      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title>test</title>
</head>
<body>
<script type="text/javascript" src="jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    function success_jsonpCallback(data){
        var html = ‘‘;
        var pos = ‘‘;
        html += ‘<ul>‘;
        $.each(data, function(k, v) {
            if(k<10){
                pos = ‘【‘ + v.city+ ‘】‘ + v.positionName + ‘(‘+ v.salary +‘) - ‘+v.companyName;
                if(pos.length > 20){
                    pos = pos.substring(0,19)+‘...‘;
                }
                html += ‘<li><a href="‘+v.posiitonDetailUrl+‘" target="_blank" title="【‘ + v.city+ ‘】‘ + v.positionName + ‘(‘+ v.salary +‘) - ‘+v.companyName+‘">‘+pos+‘</a></li>‘;
            }
        });
        $(‘#lagouData‘).html(html);
    }

    function getLagouData() {
        jQuery.ajax({
            async:false,
            url: "http://www.lagou.com/join/listW3cplus?kd=前端开发",
            type: "GET",
            dataType: "jsonp",
            jsonpCallback: ‘success_jsonpCallback‘,
            contentType: "application/jsonp; charset=utf-8",
            success: function(data) {
                success_jsonpCallback(data);
            }

        });
    }
    $(function() {
        getLagouData();
    })
   
</script>
<div id="lagouData"></div>
</body>
</html>

 

技术分享

JSONP跨域处理实例

标签:

原文地址:http://www.cnblogs.com/pcd12321/p/5454376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!