前端跨域之jsonp

demo1:

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JSONP</title>
</head>

<body id="body">
    <div id="divCustomers"></div>
    <script type="text/javascript">
        function callbackFunction(result, methodName) {
            let html = '<ul>';
            for (let i = 0; i < result.length; i++) {
                html += `<li>${result[i]}</li>`
            }
            html += '</ul>';
            document.getElementById('divCustomers').innerHTML = html;
        }
    </script>
    <script type="text/javascript" src="http://www.runoob.com/try/ajax/jsonp.php?jsoncallback=callbackFunction"></script>
</body>

</html>

demo2:

 

posted @ 2018-05-07 17:58  最好的年纪  阅读(121)  评论(0编辑  收藏  举报