zoukankan      html  css  js  c++  java
  • 【jsonp】

    function handleResponse(response) { 
        alert("You’re at IP address " + response.ip + ", which is in " + response.city + ", " + response.region_name); 
    } 
    
    var script = document.createElement("script"); 
    script.src = "http://freegeoip.net/json/?callback=handleResponse"; 
    document.body.insertBefore(script, document.body.firstChild); 
    function getVideoList(data) {
        console.log(data.retStr.length)
    }
    
    var script = document.createElement("script"); 
    script.src = "http://video.baomihua.com/play2/interface/getmobilerefvideo.html&pagetype=listCod&vid=29203608&channelid=8&type=m&jsoncallback=getVideoList"; 
    document.body.insertBefore(script, document.body.firstChild);

    返回数据格式错误,过滤换行、引号等

    中文编码

    jQuery.getJSON()
    如果URL包含字符串“callback=?”(或类似的参数,取决于服务器端 API 是如何定义的),这个请求被视为JSONP形式请求

    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script src="http://static01.baomihua.com/js/lib/jquery-1.4.4.min.js?t=20120926.js"></script>
        <script>
            // http://www.google.com.hk/?jsoncallback=getVideoList
            $.ajax({
                url: 'http://www.google.com.hk/',
                dataType: 'jsonp',
                jsonp: 'jsoncallback', // 给程序取值
                jsonpCallback: 'getVideoList', // 不产生随机数,接口缓存
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    // XMLHttpRequest.readyState
                    // XMLHttpRequest.status
                    // XMLHttpRequest.statusText
                    // textStatus
                },
                success: function(data) {}
            })
    
            // http://www.google.com.hk/?callback=jsonp1384414552005
            $.ajax({
                url: 'http://www.google.com.hk/',
                dataType: 'jsonp',
                success: function(data) {}
            })
    
            // http://www.google.com.hk/&jsonpcallback=getVideoList
            $.ajax({
                url: 'http://www.google.com.hk/&jsonpcallback=?',
                dataType: 'jsonp',
                jsonpCallback: 'getVideoList',
                success: function(data) {}
            })
    
            // http://www.google.com.hk/?jsonpccallback=jsonp1384414552006
            $.getJSON('http://www.google.com.hk/?jsonpccallback=?', function() {})
        </script>
    </body>
    </html>

  • 相关阅读:
    23种设计模式
    外部排序:选择置换、败者树
    java代理模式
    java中抽象类和接口的异同(原文作者:博客园 海子)
    java中的垃圾回收
    进程
    C标准库-数值字符串转换与内存分配函数
    文件操作
    字符串操作
    C指针(二)
  • 原文地址:https://www.cnblogs.com/jzm17173/p/3327835.html
Copyright © 2011-2022 走看看