ajax.rst 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Ajax API
  2. ========================================================
  3. .. contents::
  4. :depth: 2
  5. .. index:: loadScript
  6. .. _loadScript:
  7. K.loadScript(url [, fn])
  8. --------------------------------------------------------
  9. 加载JavaScript文件。
  10. * 参数:
  11. * string url: JavaScript URL
  12. * function fn: 回调函数
  13. * 返回: undefined
  14. 示例:
  15. .. sourcecode:: js
  16. K.loadScript('test.js', function() {
  17. console.log('ok');
  18. });
  19. .. index:: loadStyle
  20. .. _loadStyle:
  21. K.loadStyle(url)
  22. --------------------------------------------------------
  23. 加载CSS文件。
  24. * 参数:
  25. * string url: CSS URL
  26. * 返回: undefined
  27. 示例:
  28. .. sourcecode:: js
  29. K.loadStyle('test.css');
  30. .. index:: ajax
  31. .. _ajax:
  32. K.ajax(url [, fn , method , data])
  33. --------------------------------------------------------
  34. GET或POST请求。
  35. * 参数:
  36. * string url: JavaScript URL
  37. * function fn: 回调函数
  38. * string method: "GET"或"POST",默认值为"GET"
  39. * object data: POST数据,key-value格式
  40. * 返回: undefined
  41. 示例:
  42. .. sourcecode:: js
  43. //GET
  44. K.ajax('test.php', function(data) {
  45. console.log(data);
  46. });
  47. //POST
  48. K.ajax('test.php', function(data) {
  49. console.log(data);
  50. }, 'POST', {
  51. aa : 1,
  52. bb : 2
  53. });