Ext.Ajax problem submitting an XML payload as part of a PUT request

  • I am having a bit of trouble submitting some xmlData as part of a PUT request using Ext.Ajax.

    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: 'de'

    });


    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


  • Works a treat - Job done!

    Thanks for the response, I was getting a bit REST-less


  • There are other RESTful verbs available in the HTTP protocol. How about a more flexible variant:



    method = options.method 'POST';


  • Yeah, I saw you're going with it, but a fool that tries to POST with a GET deserves to be called a fool.


  • Um, because no one actually uses PUT? ;)

    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: 'de'
    });


  • @Doug, the goal of that code, placed where it is, was to specifically override GET, even if specified, when XML or JSON data are being sent. Not saying it's right or wrong, but that's the reason.


  • Yep, I'd say this (and other recent threads) show interesting use-cases for "POST and beyond".
    Might be a good time to look at those possibilities differently. [2.1?]


  • It definitely does set it to post:


    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?


  • :D

    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.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Ext.Ajax problem submitting an XML payload as part of a PUT request , Please add it free.