- The URL of the webscript you are invoking.
- The Object to be send in the request body if the method used is POST
- The Format of the Data to be Send if the method to be used is POST (optional).
- The success callback function
- The failure callback function
var actionUrl = YAHOO.lang.substitute(Alfresco.constants.PROXY_URI + "api/oase-metadata/node/{nodeRef}",
{
nodeRef: file.nodeRef.replace(":/", "")
});
Using the substitute method of the Yui framework, the URL is built up using the values passed in the JSON Object.
Prepare the success and failure callback function:
This method are used to handle the AJAX request return results. If everything goes fine the success handler is executed at the end of the AJAX request, otherwise the failure handler is called.
...
,
onSuccess: function _SuccessNotify(){
Alfresco.util.PopupManager.displayMessage( {
text : "Metadata Updated Sucessfully"
});
YAHOO.lang.later(2000,this,function(){
window.location.reload(true);
});
},
onFailure: function _FailureNotify(){
Alfresco.util.PopupManager.displayMessage( {
text : "Metadata Updated Failure"
});
}
,
...
Implement the Ajax request using the previously defined assets:
Some additional parameters are needed.
RequestContentType: is Optional but indicates here that the Object passed as parameter o the request has to be transmitted as a JSON object, not as JavaScript Native Object.
Method: Specifies the HTTP method used for processing the request. here POST is used so the data wll be transmitted in the body of a HTTP-POST Request.
DataObj: is the Object to be transmitted to the server. Its construction is similar to a JSON object definition, and usinh the requestContentType formatter value can also be sent as such.
SuccessCallback and failureCallback fields define the success an failure handlers for this AJAX request.
Alfresco.util.Ajax.request(
{
url: actionUrl,
requestContentType: Alfresco.util.Ajax.JSON,
method: Alfresco.util.Ajax.POST,
dataObj:
{
htmlid: this.id,
dataObject:
{
dateofdoc : dateofdoc,
dateofrec : dateofrec,
subjectofdoc : subjectofdoc,
typeofdoc : typeofdoc,
sendername : sendername,
senderstreet : senderstreet,
senderpostcode : senderpostcode,
sendercity: sendercity
}
},
successCallback:
{
fn: this.onSuccess,
scope: this
},
failureCallback:
{
fn: this.onFailure,
scope: this
},
execScripts: true,
});
...
},