JQuery jsonp 使用示例代码
代码如下:
<?php if (isset($_GET['jsonpcallback'])){ echo $_GET['jsonpcallback']."([{id:1,name:'aaaa1'},{id:2,name:'bbbb2'}])"; exit; } ?> <html> <script type='text/javascript' src='commons/scripts/jquery.js'></script> <script type='text/javascript'> $(function(){ $.ajax({ url:'http://localhost/test.php', dataType:"jsonp", jsonp:"jsonpcallback", success:function(data){ var $ul = $("<ul></ul>"); $.each(data,function(i,v){ $("<li/>").text(v.id + " " + v.name).appendTo($ul) }); $("#res").append($ul); } }); }); </script> <body> <div id='res'></div> </body> </html>
相关推荐
fengchao000 2020-06-17
adonislu 2020-05-16
zmosquito 2020-05-10
adonislu 2020-05-10
somebodyoneday 2020-04-22
fengchao000 2020-04-22
fengchao000 2020-04-11
Richardxx 2020-03-07
somebodyoneday 2020-03-06
fengchao000 2020-03-05
somebodyoneday 2020-02-16
xiaouncle 2020-02-13
baijinswpu 2020-01-29
fengchao000 2020-01-10
fengchao000 2019-12-25
newthon 2019-12-23
somebodyoneday 2013-07-11