This is a migrated thread and some comments may be shown as answers.

parameters for destroy can't send as urlencoded

4 Answers 141 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Vaughn
Top achievements
Rank 1
Vaughn asked on 08 Feb 2013, 06:07 PM
Hi, 

I am unable to send parameters for a DELETE (destroy) as urlencoded (it gets sent in the request body instead). I am able to send parameters for GET as urlencoded, but not for DELETE. I have the following defined in a datasource below.

Any ideas?

Cheers,
Vaughn
KendoUI version: 2012.3.1315
Platform: Phonegap 2.2.0 on Android 2.2 API (running on Android 4.2 Phone). 

----
var access_token = "something";
var url = "http://something.com/something";
read: {

  url: url, 
dataType: "json",
contentType: "application/x-www-form-urlencoded",
data: {
access_token: access_token,
}                
},
destroy: {
url: "determined at runtime",
type: "DELETE",
contentType: "application/x-www-form-urlencoded",
data: {
access_token: access_token,
},
},
parameterMap: function(options, type) {
return options;
}



4 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 12 Feb 2013, 04:08 PM
Hello Vaughn,

I assume that you are trying to perform DELETE request to a site which is not from the same domain. Are you able to perform DELETE to the site you refer with regular $.ajax(if you are able then the dataSource request should also be able to perform it)? 

More information how to enable cross-domain requests can be found in our documentation.

http://docs.kendoui.com/howto/use-cors-with-all-modern-browsers

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Vaughn
Top achievements
Rank 1
answered on 12 Feb 2013, 05:22 PM
Hello Petur,

I am performing the DELETE from an Android Phonegap app to a RESTful service running on Google App Engine. The DELETE is being sent. My problem is the WAY that extra parameters get sent. I cannot force the Datasource to send the parameters as urlencoded. I must send the parameters as urlencoded because Google App Engine (GAE) will not receive DELETE's if there are parameters/content in the body. If GAE receives a DELETE with content in the body, it will return a 404 with a message of "malformed request". They do this presumably because a DELETE should be defined entirely by the URL, and Google is enforcing this philosophy. 

So to reiterate, my problem has nothing to do with the Same Origin Policy. Other GET, POST and PUT operations are working fine (though i did not include the POST and PUT below). Parameters for my GET request are being sent urlencoded (correct behavior). I just need help to force the Datasource to send parameters (in my case the "access_token") for DELETE via the URL. Any ideas with what I am doing wrong below? 

Cheers,
Vaughn
0
Petur Subev
Telerik team
answered on 14 Feb 2013, 03:10 PM
Hello again Vaughn,

The dataSource is actually using the jQuery ajax under the hood. Can you successfully perform DELETE with $.ajax?
If possible could you share the code you have used? Basically the same options applied to $.ajax({...}) should be added to the read configuration of the dataSource.

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Vaughn
Top achievements
Rank 1
answered on 14 Feb 2013, 09:52 PM
Hi,

Surprisingly, this looks like it is an issue with Ajax. according to http://stackoverflow.com/questions/4018982/ajax-ignoring-data-param-for-delete-requests "jQuery will only append parameters to the querystring for GET requests only". This is surprising because Microsoft (http://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request) and Google (http://stackoverflow.com/questions/3373657/app-engine-400-your-client-has-issued-a-malformed-or-illegal-request) forbid a DELETE request to have an entity body. Oh well. 

Sorry Petur for the trouble.

For those who need to work around this, you need to manually attach the parameters to the URL string and to remove sending data in the request body. You will thus need the following in your dataSource.transport definition:

var dataSource = new kendo.data.DataSource({
transport: {
destroy: {
url: "determined at runtime with whatever parameters you need to include",
type: "DELETE",
},
parameterMap: function(options, type) {
  if (type == "destroy") {
    return;
  }
}
}
});

And then you would have your delete function something like the following:

$("#button-delete").click(function() {
var itemID = selectedItem.get("id");
var url = generateURL(itemID);
url += "?access_token=" + getAccessToken(); // added because Ajax doesnt do it
dataSource.transport.options.destroy.url = url;
dataSource.remove(selectedItem);
dataSource.sync();
});

Cheers, 
Vaughn




Tags
Data Source
Asked by
Vaughn
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Vaughn
Top achievements
Rank 1
Share this question
or