remotejsonp.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Remote JSONP - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>Remote JSONP</h2>
  14. <p>This sample shows how to use JSONP to retrieve data from a remote site.</p>
  15. <div style="margin:20px 0"></div>
  16. <div class="easyui-panel" style="width:100%;max-width:400px;padding:30px 60px;">
  17. <div style="margin-bottom:20px">
  18. <input class="easyui-combobox" style="width:100%;" data-options="
  19. loader: myloader,
  20. mode: 'remote',
  21. valueField: 'id',
  22. textField: 'name',
  23. label: 'State:',
  24. labelPosition: 'top'
  25. ">
  26. </div>
  27. </div>
  28. <script>
  29. var myloader = function(param,success,error){
  30. var q = param.q || '';
  31. if (q.length <= 2){return false}
  32. $.ajax({
  33. url: 'http://gd.geobytes.com/AutoCompleteCity',
  34. dataType: 'jsonp',
  35. data: {
  36. q: q
  37. },
  38. success: function(data){
  39. var items = $.map(data, function(item,index){
  40. return {
  41. id: index,
  42. name: item
  43. };
  44. });
  45. success(items);
  46. },
  47. error: function(){
  48. error.apply(this, arguments);
  49. }
  50. });
  51. }
  52. </script>
  53. </body>
  54. </html>