首页 > 代码库 > jsonp示列

jsonp示列

前端代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>test page</title>
        <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    </head>
    <body>
        1
    </body>
</html>
<script type="text/javascript">
    $(function() {
        $.ajax({
            url: "http://han.com/jsonp.php?callback=?",
            data: "p1=1&p2=2",
            type: "get",
            timeout: 15000,
            dataType: "jsonp",  // not "json" we‘ll parse
            // jsonp: "callbackd",
            success:function (data) {
                console.log(data);
            }
        })
    })
</script>

 

后端php代码

<?php

$callback = isset($_GET[‘callback‘]) ? $_GET[‘callback‘] : ‘‘;

$data = http://www.mamicode.com/["(" . json_encode($data) . ")";

  

jsonp示列