Ext.Ajax problem submitting an XML payload as part of a PUT request
I'm trying to use the extremely handy Ext.Ajax.request method, but I've noticed that if you supply anthing in the xmlData option, it automagically submits a POST request.
Unfortunately, our service requires me to submit a PUT request with an XML payload :(
Here's the code:
Ext.Ajax.request({
url: 'testrest.php',
method: 'PUT',
headers: {'Content-Type': 'text/xml'},
success: function(response, opts) { Ext.Msg.alert('Sucess', 'Update has been successful'); },
xmlData: '
});
So we always see a POST on the server, even though I explicitly set a PUT method
However, if I remove the xmlData (or event use a null xmlData) we correctly see the PUT request on the server.
Is this a wee bug or am I being stupid? Perhaps someone has a workaround?
Any help would be greatly appreciated. (Sorry about the code formatting!)
G
Thanks for the response, I was getting a bit REST-less
method = options.method 'POST';
It's there to default it since you can't send xml or JSON to the server via GET, but PUT was not considered. Does this work for you?
Ext.lib.Ajax.request = function(method, uri, cb, data, options) {
if(options){
var hs = options.headers;
if(hs){
for(var h in hs){
if(hs.hasOwnProperty(h)){
this.initHeader(h, hs[h], false);
}
}
}
if(options.xmlData){
this.initHeader('Content-Type', 'text/xml', false);
method = (options.method == 'PUT' ? 'PUT' : 'POST');
data = options.xmlData;
}else if(options.jsonData){
this.initHeader('Content-Type', 'text/javascript', false);
method = (options.method == 'PUT' ? 'PUT' : 'POST');
data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
}
}
return this.asyncRequest(method, uri, cb, data);
};
Ext.Ajax.request({
url: 'testrest.php',
method: 'PUT',
headers: {'Content-Type': 'text/xml'},
success: function(response, opts) { Ext.Msg.alert('Sucess', 'Update has been successful'); },
xmlData: '
});
Might be a good time to look at those possibilities differently. [2.1?]
if(options.xmlData){
this.initHeader('Content-Type', 'text/xml', false);
method = 'POST';
data = options.xmlData;
}
Devs, what is the reason behind setting the method to post in this case?
Well, we didn't actually make that change in Ext -- it was left as an override here, based on the rarity of PUT being used. However, based on the REST thread currently going on, maybe this would make sense to change per your suggestion.
#If you have any other info about this subject , Please add it free.# |

