Ajax.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @class Ext.Ajax
  3. * @singleton
  4. * @markdown
  5. A singleton instance of an {@link Ext.data.Connection}. This class
  6. is used to communicate with your server side code. It can be used as follows:
  7. Ext.Ajax.request({
  8. url: 'page.php',
  9. params: {
  10. id: 1
  11. },
  12. success: function(response){
  13. var text = response.responseText;
  14. // process server response here
  15. }
  16. });
  17. Default options for all requests can be set by changing a property on the Ext.Ajax class:
  18. Ext.Ajax.timeout = 60000; // 60 seconds
  19. Any options specified in the request method for the Ajax request will override any
  20. defaults set on the Ext.Ajax class. In the code sample below, the timeout for the
  21. request will be 60 seconds.
  22. Ext.Ajax.timeout = 120000; // 120 seconds
  23. Ext.Ajax.request({
  24. url: 'page.aspx',
  25. timeout: 60000
  26. });
  27. In general, this class will be used for all Ajax requests in your application.
  28. The main reason for creating a separate {@link Ext.data.Connection} is for a
  29. series of requests that share common settings that are different to all other
  30. requests in the application.
  31. */
  32. Ext.define('Ext.Ajax', {
  33. extend: 'Ext.data.Connection',
  34. singleton: true,
  35. /**
  36. * @cfg {Object} extraParams @hide
  37. */
  38. /**
  39. * @cfg {Object} defaultHeaders @hide
  40. */
  41. /**
  42. * @cfg {String} method @hide
  43. */
  44. /**
  45. * @cfg {Number} timeout @hide
  46. */
  47. /**
  48. * @cfg {Boolean} autoAbort @hide
  49. */
  50. /**
  51. * @cfg {Boolean} disableCaching @hide
  52. */
  53. /**
  54. * @property {Boolean} disableCaching
  55. * True to add a unique cache-buster param to GET requests. Defaults to true.
  56. */
  57. /**
  58. * @property {String} url
  59. * The default URL to be used for requests to the server.
  60. * If the server receives all requests through one URL, setting this once is easier than
  61. * entering it on every request.
  62. */
  63. /**
  64. * @property {Object} extraParams
  65. * An object containing properties which are used as extra parameters to each request made
  66. * by this object. Session information and other data that you need
  67. * to pass with each request are commonly put here.
  68. */
  69. /**
  70. * @property {Object} defaultHeaders
  71. * An object containing request headers which are added to each request made by this object.
  72. */
  73. /**
  74. * @property {String} method
  75. * The default HTTP method to be used for requests. Note that this is case-sensitive and
  76. * should be all caps (if not set but params are present will use
  77. * <tt>"POST"</tt>, otherwise will use <tt>"GET"</tt>.)
  78. */
  79. /**
  80. * @property {Number} timeout
  81. * The timeout in milliseconds to be used for requests. Defaults to 30000.
  82. */
  83. /**
  84. * @property {Boolean} autoAbort
  85. * Whether a new request should abort any pending requests.
  86. */
  87. autoAbort : false
  88. });