remotejsonp.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. <input class="easyui-combobox" style="width:250px" data-options="
  17. loader: myloader,
  18. mode: 'remote',
  19. valueField: 'id',
  20. textField: 'name'
  21. ">
  22. <script>
  23. var myloader = function(param,success,error){
  24. var q = param.q || '';
  25. if (q.length <= 1){return false}
  26. $.ajax({
  27. url: 'http://ws.geonames.org/searchJSON',
  28. dataType: 'jsonp',
  29. data: {
  30. featureClass: "P",
  31. style: "full",
  32. maxRows: 20,
  33. name_startsWith: q
  34. },
  35. success: function(data){
  36. var items = $.map(data.geonames, function(item){
  37. return {
  38. id: item.geonameId,
  39. name: item.name + (item.adminName1 ? ', ' + item.adminName1 : '') + ', ' + item.countryName
  40. };
  41. });
  42. success(items);
  43. },
  44. error: function(){
  45. error.apply(this, arguments);
  46. }
  47. });
  48. }
  49. </script>
  50. </body>
  51. </html>