jQuery中的JSONP

jQuery提供的$.ajax()函数,除了可以发起真正的Ajax数据请求之外,还能够发起JSONP数据请求,例如:

 

 示例代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/js文件/jquery-3.6.0.js"></script>
</head>

<body>

</body>
<script>
    $(function () {
        // 发起JSONP的请求
        $.ajax({
            url: 'http://ajax.frontend.itheima.net:3006/api/jsonp?name=zs&age=20',
            // 代表我们要发起的JSONP数据请求
            dataType: 'jsonp',
            success: function (res) {
                console.log(res);
            }
        })
    })
</script>

</html>

 

posted @ 2022-05-03 15:50  今天穿秋裤了吗  阅读(195)  评论(0)    收藏  举报