首页 > 代码库 > jQuery 使用 JSONP

jQuery 使用 JSONP

<script type="text/javascript">
function callbackFunction(result, methodName)
{
    var html = ‘<ul>‘;
    for(var i = 0; i < result.length; i++)
    {
        html += ‘<li>‘ + result[i] + ‘</li>‘;
    }
    html += ‘</ul>‘;
    document.getElementById(‘divCustomers‘).innerHTML = html;
}
</script>

  

 

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JSONP 实例</title>
    <script src="http://cdn.static.runoob.com/libs/jquery/1.8.3/jquery.js"></script>    
</head>
<body>
<div id="divCustomers"></div>
<script>
$.getJSON("http://www.runoob.com/try/ajax/jsonp.php?jsoncallback=?", function(data) {
    
    var html = ‘<ul>‘;
    for(var i = 0; i < data.length; i++)
    {
        html += ‘<li>‘ + data[i] + ‘</li>‘;
    }
    html += ‘</ul>‘;
    
    $(‘#divCustomers‘).html(html); 
});
</script>
</body>
</html>

  

jQuery 使用 JSONP