客户端页面完整代码
<!DOCTYPEhtml><html><head><metacharset="utf-8"><title>JSONP 实例title>head><body><divid="divCustomers">div><scripttype="text/javascript">
functioncallbackFunction(result, methodName){ varhtml = '
-
'
;
for
(
var
i
=
0
;
i
<
result
.
length
;
i
++
)
{
html
+=
'
- ' + result[i] + ' ' ; } html += '
'; document.getElementById('divCustomers').innerHTML = html;}
script><scripttype="text/javascript"src="https://www.runoob.com/try/ajax/jsonp.php?jsoncallback=callbackFunction">script>body>html>
jQuery 使用 JSONP
以上代码可以使用 jQuery 代码实例:
<!DOCTYPEhtml><html><head> <metacharset="utf-8"> <title>JSONP 实例title> <scriptsrc="https://cdn.static.runoob.com/libs/jquery/1.8.3/jquery.js">script> head><body><divid="divCustomers">div><script>
$.getJSON("https://www.runoob.com/try/ajax/jsonp.php?jsoncallback=?", function(data){ varhtml = '
-
'
;
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
html
+=
'
- ' + data[i] + ' ' ; } html += '
'; $('#divCustomers').html(html); });
script>body>html>