wc.service.declare (initProperties)

The wc.service.declare function declares a new AJAX service with the specified ID. In WebSphere Commerce, a service is a server URL that performs a server object create, update, delete or other server processing. When needed, a WebSphere Commerce server URL is called using AJAX in the JavaScript code. When the service completes successfully, a JSON object containing all the response properties of the URL request is returned to successHandler (the success response) or failureHandler (the failure response) defined JavaScript function. In addition, a model changed event is sent to any subscribed listeners if the service completes successfully. In this case, the modelChanged and modelChanged/actionId Dojo events are published.

Example

wc.service.declare({
  id: "AjaxAddOrderItem",
  actionId: "AjaxAddOrderItem",
  url: "AjaxOrderChangeServiceItemAdd",
  formId: "",

  successHandler: function(serviceResponse) {
    alert("success");	
  },
  
  failureHandler: function(serviceResponse) {
    if (serviceResponse.errorMessage) {
      alert(serviceResponse.errorMessage);
    }
  }
});

Parameters

initProperties
(Object) Contains any of the initialization parameters.
id
(String) The unique ID of this service.
actionId
(String) An identifier for the action performed by this service. This value is used in the construction of the topic name for the model changed event. The model changed event name is in the following form: modelChanged/actionId.
url
(String) The URL for this service.
formId
(String) The ID of the form element that is posted to the URL. It is not necessary, however, to associate a service with a form element.
successHandler: function (serviceResponse)
Summary: Performs processing after a successful service invocation.
Description: This function is called after a successful service invocation to allow for any post-service processing. The default implementation does not perform any post-service processing. This function can be replaced by passing in a new version with the initProperties Object when the service is constructed.
serviceResponse: (Object) The service response object is the JSON Object returned by the service invocation.
failureHandler: function (serviceResponse)
Summary: Performs processing after a failed service invocation.
Description: This function is called after a failed service invocation to handle any error processing. The default implementation alerts the user with the error message found in the service response object. This function can be replaced by passing in a new version with the initProperties Object when the service is constructed.
serviceResponse: (Object) The service response object is the JSON Object returned by the service invocation.