美文网首页
jsonp例子

jsonp例子

作者: z_j_r | 来源:发表于2017-10-31 18:14 被阅读0次

前言:

成功等于目标,其他都是这句话的注解

--------------------------------正文---------------------------------

js代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
        function abc(json){
            alert(json.s);
        }
    </script>
    <script src="https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=a&cb=abc"></script>
</head>
<body>
    
</body>
</html>

jQuery代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="js/jquery-1.9.1.min.js"></script>
</head>
<body>
    <script>
        $(document).ready(function(){
            $.ajax({
                url:'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',
                data:{
                    wd: 'a'
                },
                dataType: 'jsonp',
                jsonp: 'cb'            // cb 是回调函数
            }).then(function(res){
                alert(res.s);
            },function(){
                alert('!ok')
            });
        });
    </script>
</body>
</html>

相关文章

网友评论

      本文标题:jsonp例子

      本文链接:https://www.haomeiwen.com/subject/yezbpxtx.html