银河湖北快三计划—官方网址22270.COM鈥擩SONP 鏁欑▼

鏈珷鑺傛垜浠皢鍚戝ぇ瀹朵粙缁 银河湖北快三计划—官方网址22270.COM鈥擩SONP 鐨勭煡璇嗐

银河湖北快三计划—官方网址22270.COMJsonp(JSON with Padding) 鏄 json 鐨勪竴绉"浣跨敤妯″紡"锛屽彲浠ヨ缃戦〉浠庡埆鐨勫煙鍚嶏紙缃戠珯锛夐偅鑾峰彇璧勬枡锛屽嵆璺ㄥ煙璇诲彇鏁版嵁銆

涓轰粈涔堟垜浠粠涓嶅悓鐨勫煙锛堢綉绔欙級璁块棶鏁版嵁闇瑕佷竴涓壒娈婄殑鎶鏈( 银河湖北快三计划—官方网址22270.COM鈥擩SONP )鍛紵杩欐槸鍥犱负鍚屾簮绛栫暐銆

鍚屾簮绛栫暐锛屽畠鏄敱 Netscape 鎻愬嚭鐨勪竴涓憲鍚嶇殑瀹夊叏绛栫暐锛岀幇鍦ㄦ墍鏈夋敮鎸 JavaScript 鐨勬祻瑙堝櫒閮戒細浣跨敤杩欎釜绛栫暐銆


银河湖北快三计划—官方网址22270.COM鈥擩SONP 搴旂敤

1. 鏈嶅姟绔 银河湖北快三计划—官方网址22270.COM鈥擩SONP 鏍煎紡鏁版嵁

濡傚鎴锋兂璁块棶 : http://alevg.com/try/ajax/jsonp.php?jsoncallback=callbackFunction

鍋囪瀹㈡埛鏈熸湜杩斿洖鏁版嵁锛歔"customername1","customername2"]銆

鐪熸杩斿洖鍒板鎴风鐨勬暟鎹樉绀轰负: callbackFunction(["customername1","customername2"])銆

鏈嶅姟绔枃浠 jsonp.php 浠g爜涓猴細

jsonp.php 鏂囦欢浠g爜

<?php header('Content-type: application/json'); //鑾峰彇鍥炶皟鍑芥暟鍚 $jsoncallback = htmlspecialchars($_REQUEST ['jsoncallback']); //json鏁版嵁 $json_data = '["customername1","customername2"]'; //杈撳嚭jsonp鏍煎紡鐨勬暟鎹 echo $jsoncallback . "(" . $json_data . ")"; ?>

2. 瀹㈡埛绔疄鐜 callbackFunction 鍑芥暟

<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>

椤甸潰灞曠ず

<div id="divCustomers"></div>

瀹㈡埛绔〉闈㈠畬鏁翠唬鐮

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>银河湖北快三计划—官方网址22270.COM鈥擩SONP 瀹炰緥</title> </head> <body> <div id="divCustomers"></div> <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> <script type="text/javascript" src="http://alevg.com/try/ajax/jsonp.php?jsoncallback=callbackFunction"></script> </body> </html>

jQuery 浣跨敤 JSONP

浠ヤ笂浠g爜鍙互浣跨敤 jQuery 浠g爜瀹炰緥锛

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>银河湖北快三计划—官方网址22270.COM鈥擩SONP 瀹炰緥</title> <script src="http://cdn.static.alevg.com/libs/jquery/1.8.3/jquery.js"></script> </head> <body> <div id="divCustomers"></div> <script>
$.getJSON("http://alevg.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>