Ajax utilities are contained in the mvcct-controls package file mvcct.controls.ajax.js.
with AMD or Node.js loading the object containing them may be obtained by requiring mvcct.controls.ajax.
Ajax loading utilities
- .getContent(el, url, bearerToken, onSuccess, errorMessageF, onError, onCompleted, onProgress)
It perform an ajax get operation on
elis the Html node whose content might be affected when the operation is completed.
elis passed as the unique argument to
onCompletedthat is called when the operation is succesfully or unsuccesfully completed.
onCompletedmay be used to remove an user interaction block previously applied to
getContent. If not null
bearerTokenis added to the header as bearer token (in order to authenticate the request).
onErroris called passing it an error message in case of any error, namely: communication error, error status code returned by the server, or in case server response starts with '#', in which case the remainder of the response is assumed to be a an error message returned by the server. In case of error status code the error message is obtained by passing the status code to
errorMessageFand taking the result returned. In case of success the whole response is passed to
onSuccessas a string.
onProgressis used as
onprogresproperty of the
XMLHttpRequestobject that performs the ajax call. Thus, it receives an event object with the progress state as its unique argument
- .postForm(inForm, url, extraData, onSuccess, errorMessageF, onError, onCompleted, onProgress, onStart)
inForm, if, it is a form, or a form contained in
inFormwith an ajax call. If
urlis not null it is used instead of the url specified in the form. If not null extradata must be a string that specifies param/value pairs in query string format (ie like 'par1=val1&par2=val2...'); it is concatenated with the result of the serialization of all input fileds contained in the form.
onStartis called immediately before starting the ajax operation and is passed
inFormas its unique argument. All other parameters have the same meaning as in the
- .postJson(el, url, data, bearerToken, onSuccess, errorMessageF, onError, onCompleted, onProgress)
ulrafter having converted it into a Json string. All other parameters have the same meaning as in the
If a link is added the Html5 attribute
an ajax GET call to the url contained in the link, is started when the link is clicked. All call features
are specified in the declaration of
Endpoints are declared with:
- .addJsonEndpoint(name, bearerToken, onSuccess, errorMessageF, onError, onStart, onCompleted, onProgress)
nameis the endpoint name to be referred in the link. The ajax call is expected to return Json, and in case of success data obtained by parsing the Json received are passed as unique argument to
onSuccess. All other parameters have the same meaning as in
postForm. The node passed to both
onCompletedis the link itself.
remove a previously defined endpoint called
name. It must be called when all links referring to it have been removed from the dom, in order to avoid memory leaks.