• ng.XHR is not available in the Lite version

new ng.XHR (String url, Object xhr_prop) vs. 1.1.0 FULL ONLY

The XHR class is used for Ajax requests.

Parameters

String url Required vs. 1.1.0 FULL ONLY
The request URL, must be in the same domain for cross domain security.
Object xhr_prop vs. 1.1.0 FULL ONLY
An optional object that holds the ng.XHR properties.

Examples

Using ng.XHR(url, param)
Demo:
Server time will show below:

Inheritance Tree

This class inherits the following classes and all their methods and properties. It's recommended to check if any private properties/options are defined before using them. The complete list of inheritted methods and events are listed below the current object Custom Events.
ng.Events ()
ng.XHR (url, xhr_prop)

Methods

Function ng.XHR.request (method, prcs_param) vs. 1.1.0 FULL ONLY
Send the XHR request to the server.
Function ng.XHR.get (prcs_param) vs. 1.1.0 FULL ONLY
Same as the ng.XHR.request() but uses the GET method.
Function ng.XHR.post (prcs_param) vs. 1.1.0 FULL ONLY
Same as the ng.XHR.request() but uses the POST method.
Function ng.XHR.cancel () vs. 1.1.0 FULL ONLY
Cancels the Ajax request and fires the onCancel event.
Function ng.XHR.abort () vs. 1.1.0 FULL ONLY
Same as the ng.XHR.cancel() method, but does not fire any event.
 
Function ng.XHR.set_url (url) vs. 1.1.0 FULL ONLY
Sets the URL for the request.
Function ng.XHR.get_url () vs. 1.1.0 FULL ONLY
Gets the URL for the request.
Function ng.XHR.set_param (param) vs. 1.1.0 FULL ONLY
Sets the query parameters object.
Function ng.XHR.get_param () vs. 1.1.0 FULL ONLY
Gets the param property for the request.
Function ng.XHR.set_async (async) vs. 1.1.0 FULL ONLY
Sets the async property for the request.
Function ng.XHR.get_async () vs. 1.1.0 FULL ONLY
Gets the async property for the request.
Function ng.XHR.set_encoding (encoding) vs. 1.1.0 FULL ONLY
Sets the encoding property for the request.
Function ng.XHR.get_encoding () vs. 1.1.0 FULL ONLY
Gets the encoding property for the request.
Function ng.XHR.set_eval_script () vs. 1.1.0 FULL ONLY
Sets the eval_script property for the request.
Function ng.XHR.get_eval_script () vs. 1.1.0 FULL ONLY
Gets the eval_script property for the request.
Function ng.XHR.set_timeout (timeout) vs. 1.1.0 FULL ONLY
Sets the timeout property for the request.
Function ng.XHR.get_timeout () vs. 1.1.0 FULL ONLY
Gets the timeout property for the request.
Function ng.XHR.set_cache (cache) vs. 1.1.0 FULL ONLY
Sets the cache property for the request.
Function ng.XHR.get_cache () vs. 1.1.0 FULL ONLY
Gets the cache property for the request.
Function ng.XHR.set_header (key, val) vs. 1.1.0 FULL ONLY
Sets a specific request header using a key and value.
Function ng.XHR.get_header (key) vs. 1.1.0 FULL ONLY
This methods will try to get the response header for the request. If the request was not sent yet, it will try to get the header value from the headers property.
Function ng.XHR.get_headers () vs. 1.1.0 FULL ONLY
Gets the headers property for the request.
 
Function ng.XHR.submit_form (form) vs. 1.1.5 FULL ONLY
Submit a form using Ajax. This method uses the FormData object when supported to post data; otherwise it serialize the form. If uploading a file and FormData is unsupported, the form is submitted into a hidden iframe and the results are passed to the XHR events.
Function ng.XHR.clear_header (key) vs. 1.1.5 FULL ONLY
Remove a header from the request before sending it.
Function ng.XHR.get_status () vs. 1.1.0 FULL ONLY
Get the ready status code for the request.
Function ng.XHR.get_status_text () vs. 1.1.0 FULL ONLY
Gets the ready status text for the request.
Function ng.XHR.get_object () vs. 1.1.5 FULL ONLY
Returns the native XMLHttpRequest object.

Custom Events

In the events' functions, the this will refer to the class object.
Event onRequest vs. 1.1.0 FULL ONLY
Fires right before the request is sent. From version 1.1.5, When this event is fired, a window onXHRRequest is also fired. The method for the window event will receive the entire ng.XHR object as a parameter. Example on using the window event.
ng.get('window')..add_event('onXHRRequest', function (xhr) {
    // do something
});
Event onSuccess vs. 1.1.0 FULL ONLY
Fires when the request is complete and successfull. The function for this event will receive an object as a parameter with the response text and response xml as the following:
  • obj.text: the requested text
  • obj.xml: the requested xml
  • obj.response vs. 1.1.5 FULL ONLY: the requested response (e.g. blob)
From version 1.1.5, When this event is fired, a window onXHRSuccess is also fired. The method for the window event will receive the entire ng.XHR object as a parameter.
Event onFail vs. 1.1.0 FULL ONLY
Fires when the request is complete and failed. The function for this event will receive the XHR status code (e.g. 401 for Access denied). From version 1.1.5, When this event is fired, a window onXHRFail is also fired. The method for the window event will receive the entire ng.XHR object as a parameter. As of version 1.2.2 a second parameter is passed with the status text (e.g. Not Found).
Event onComplete vs. 1.1.0 FULL ONLY
Fires when the request is complete regardless if it failed or successed. This function will either receive the response object from the success function or the status code from the fail function depending on the request result. From version 1.1.5, When this event is fired, a window onXHRComplete is also fired. The method for the window event will receive the entire ng.XHR object as a parameter.
Event onTimeout vs. 1.1.0 FULL ONLY
Fires when the request times out. From version 1.1.5, When this event is fired, a window onXHRTimeout is also fired. The method for the window event will receive the entire ng.XHR object as a parameter.
Event onCancel vs. 1.1.0 FULL ONLY
Fires when the request is cancelled using the ng.XHR.cancel() method. From version 1.1.5, When this event is fired, a window onXHRCancel is also fired. The method for the window event will receive the entire ng.XHR object as a parameter.
Event onProgress vs. 1.1.5 FULL ONLY
This event will only fire if the browser support native XHR progress events. This events can be used to stream data as they become available. This event method will receive an object with different status responses (e.g. {status:'progress'}
Additionally, the object will contain additional information based on the status as the following:

pending, complete, error and cancel (some of the values below might be empty or null).
  • text: any returned text from the server
  • xml: any returned xml from the server
  • response: any returned response from the server

progress
  • text: any returned text from the server
  • xml: any returned xml from the server
  • response: any returned response from the server
  • total: the total size of data being sent
  • loaded: the loaded size of data already sent
  • percent: a percentage value of the loaded value

ng.Events () Methods

Some of these methods might be overriden by the inheriting class.
Function ng.Events.add_event (evt, func) vs. 1.1.0 Full+Lite
The add_event method will attach an event listener to an object. When the event is fired, the listeners functions will be executed on last added first run approach.
Function ng.Events.add_events (obj) vs. 1.1.0 Full+Lite
This method works the same way as Events.add_event(evt, func) except it takes an object with a list of events and functions.
Function ng.Events.remove_event (evt, func) vs. 1.1.0 Full+Lite
Remove the function func from the event evt queue. When adding the event, you should add the function by reference. Anonymous functions cannot be removed.
Function ng.Events.remove_events (obj) vs. 1.1.0 Full+Lite
This method works the same way as Events.remove_event(evt, func) except it takes an object with a list of events and functions.
Function ng.Events.clear_events (evt) vs. 1.1.0 Full+Lite
Remove all the functions under the event name evt.
Function ng.Events.clear_all_events () vs. 1.1.0 Full+Lite
This function works the same way Events.clear_events(evt) except it removes all the events attached to the object.
Function ng.Events.fire_event (evt_nm, args, evt) vs. 1.1.0 Full+Lite
Executes all the functions in the event evt_nm queue. Functions are executed in lasted added first exectued order.