ajax() is a shortcut function for performing a synchronous or an asynchronous Ajax request.
There are 2 ways this function can be used:
ajax(string url, function handler)
In the first form, the function accepts parameters url and handler. Url is a required string value that sets the URL for the request. Query string parameters can be included on the URL. handler is an optional function. If a handler function is passed, the function will be invoked upon successful request completion. The request method is always GET when using this form.
In the second form, the function accepts a single configuration object as a parameter. The object is used to set all options of the request in the same way this is done using the pui.AjaxRequest object. The only exceptions are that the async and onsuccess properties of the object are not used. Instead, the parameter can have an optional handler property that can be used to specify a function to call on completion of the request.
In either form of the function, an asynchronous request will be performed if the handler function is provided. The response text of the request is passed as a parameter to the handler function.
If the handler function is omitted, a synchronous request will be performed, and the response text will be returned from the function.
In this example, the ajax() function is used to perform a synchronous GET request, passing parameters on the URL:
In this example, the ajax() function is used to perform an asynchronous POST request.