I had a problem linking up dojo/xhrPut and Catalyst::Controller::REST. As always, the answer was in the documentation, but I didn’t see it.
Catalyst::Controller::REST docs say that:
The HTTP POST, PUT, and OPTIONS methods will all automatically deserialize the contents of $c->request->body based on the requests content-type header. A list of understood serialization formats is below.
And the docs for dojo/xhrPut point to those for dojo/xhrGet for parameters, which include:
headers
A JavaScript object of name/string value pairs. These are the headers to send as part of the request. For example, you can use the headers option to set the Content-Type, X-Method-Override, or Content-Encoding headers of the HTTP request.
This parameter is optional
So all I had to do in my javascript code is
var xhrArgs = {
url: ajaxurls.sort + '/' + editing.id,
putData: dojo.toJson(data),
handleAs: "json",
headers: {'Content-Type':'application/json'},
load: function(data){
// don't really need to do anything here
// uncomment for testing
// console.log("new sort order put to server");
},
error: function(error){
alert('warning, edits were not saved properly. Proceed with caution');
}
}
//Call the asynchronous xhrPost
var deferred = dojo.xhrPut(xhrArgs);
And the controller magically started to work as expected. Hooray, git commit and all that, but it is time to go to sleep and actually get things working some other day.