Sys.Data.DataService.remove Method

Deletes data through the data service.

Syntax

remove: function(item, resourceUri, succeededCallback, failedCallback, userContext)

Usage

var a = exampleDataService.remove(item, resourceUri, succeededCallback, failedCallback, userContext);

Parameter

Definition

item

(Optional) A JavaScript object with a __metadata property specifying the resource URI of the data item to be removed.

resourceUri

(Optional) The resource URI of the data item to be removed.

succeededCallback

(Optional) The function to execute when the remove operation succeeds.

failedCallback

(Optional) The function to execute when the remove operation fails.

userContext

(Optional) The state object for this operation.

Return Value

The Sys.Net.WebRequest object that performed the remove operation.

Remarks

Use the remove method to delete data through a data service. The remove method immediately executes a single remove operation. If you must execute more than one operation as a single batch, use the createActionSequence method.

To delete data, you can pass the data to delete as a JavaScript object in the item parameter or you can include the data identifier in the resourceUri parameter. The following example shows how to pass the identifier in the resourceUri parameter. The code removes data from the Customers table of the Northwind database based on the user's input.

var customerId = document.getElementById("TextCustomerId").value;
var ds = new Sys.Data.DataService("/Northwind.svc");
ds.remove(null, "/Customers('" + customerId + "')", cbSuccess, cbFailure);

The signatures for the callback functions should be similar to the following code:

function callbackSucceeded(result, context, operation)
function callbackFailed(error, context, operation)

The functions you assign to the callback functions must accept three parameters. For the succeeded callback function, the first parameter always contains null. For the failed callback function, the first parameter contains the error returned by the data service. The second parameter contains the state object for the data operation. The third parameter contains a description of the operation that was performed. For remove operations, the third parameter contains remove.

This topic is ASP.NET Extensions documentation and is unsupported by Microsoft. Blank topics are included as placeholders and existing content is subject to change in future releases.