• JSONP跨域处理实例


    <!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>

  • 相关阅读:
    链表-(1)
    爬虫(10-3)验证码图片识别
    爬虫10-2(多线程爬虫)
    分布式爬虫系统的架构(19)
    pipenv管理Python虚拟环境
    peewee-async集成到tornado
    Python3笔记051
    Python3笔记050
    Python3笔记049
    Python3笔记048
  • 原文地址:https://www.cnblogs.com/pcd12321/p/5454376.html
Copyright © 2020-2023  润新知