跨域

极客数据 https://www.jisuapi.com/

jQuery Ajax jsonp跨域实例:借用极客数据,做了一个号码归属地的查询。

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>跨域</title>
        <script src="http://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
    </head>
    <body>
        <input type="text" id="telephone" placeholder="电话号码">
        <button class="btn">提交</button>
    </body>
</html>
<script type="text/javascript">
    $(function () {
        $("#btn").on("click", function(){
            var tel = $("#telephone").val();
            $.ajax({
                type: "get",
                url: "http://api.jisuapi.com/shouji/query",
                data: "appkey=b0ea36f639fb6a03&shouji="+tel,
                dataType:jsonp,
                success: function(msg){
                    console.log(msg)
                }
            });
        });
    })
</script>

 

posted @ 2017-04-02 07:32  最爱小虾  阅读(169)  评论(0编辑  收藏  举报