Marlowe
Marlowe

Reputation: 432

Delete entry from database with WinJS and OData

I'm trying to delete an entry from the database by odata. I get the error message

{"error":{"code":"","message":{"lang":"en-US","value":"Bad Request - Error in query syntax."}}}

my code:

function deleteMonthEntry() {

    var item = actMonthEntries.getItem(listIndex);
    var queryString = "Stundens(" + item.data.datensatz_id + ")?$format=json";
    var requestUrl = serviceUrl + queryString;

    WinJS.xhr({
        type: "delete",
        url: requestUrl,
        headers: {
            "Content-type": "application/json"
        }
    }).done(
          function complete(response) {

          },
          function (error) {
              console.log(error);
          }
       );
}

My request URL looks like this:

    requestUrl = "http://localhost:51893/TimeSheetWebservice.svc/Stundens(305233)?$format=json"

Thanks Marlowe

Upvotes: 0

Views: 327

Answers (2)

Marlowe
Marlowe

Reputation: 432

At least I found the solution:

I've entered an filter request to my service like this:

TimeSheetWebservice.svc/Stundens?$filter=datensatz_id eq 305221

this returned the correct entry with this link:

TimeSheetWebservice.svc/Stundens(305221M)

So if I enter a M after the ID, everything works fin. But I have no idea where this M comes from.

Can anyone tell me the reason for this M? It does not belong to the ID. The ID is this 305221

Marlowe

Upvotes: 1

Jen S
Jen S

Reputation: 4555

Are you sure the server you're talking to supports the $format query option? Many don't. I would try removing that part of the request URI, and instead modify your headers value to specify an Accept header:

headers: {
    "Content-Type": "application/json",
    "Accept": "application/json"
}

For servers where $format is allowed, giving it a json value is equivalent to providing an Accept header with the application/json MIME type.

In general, for a DELETE operation, the Accept header or $format value only matters for error cases. With a successful DELETE, the response payload body will be empty, so there's no need for the server to know about your format preference.

Upvotes: 0

Related Questions