标签:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jsonp</title> <script type="text/javascript" src="./js/jquery-1.8.3.min.js"></script> <!-- <script> var flightHandler = function(data){ alert("你查询的航班结果是:票价" + data.price + ‘元。余票‘ + data.tickets + ‘张。‘) } var url = "http://www.plants.cn/flightResult.php?code=CA1998&callback=flightHandler"; var script = document.createElement(‘script‘); script.setAttribute(‘src‘, url); document.getElementsByTagName(‘head‘)[0].appendChild(script); </script> --> <script> $(function(){ var url = "http://www.plants.cn/flightResult.php?code=CA1998&callback=flightHandler"; $.ajax({ type: "get", async: false, url: url, dataType: "jsonp", jsonp: "callback", success: function(data){ alert("你查询的航班结果是:票价" + data.price + ‘元。余票‘ + data.tickets + ‘张。‘) } }) }) </script> </head> <body> </body> </html>
flightResult.php
$code = $_GET[‘code‘]; $callback = $_GET[‘callback‘]; $result = ‘{"code":"CA1998", "price":"1780", "tickets":5}‘; echo "$callback($result)";
标签:
原文地址:http://www.cnblogs.com/tianxintian22/p/5726799.html