Send Back Data as URL Rather than Form Data

Send Back Data as URL Rather than Form Data

CoreBioCoreBio Posts: 12Questions: 5Answers: 0

Hello,

I am currently running into an issue where in datatables editor, when I try and delete a row using HTTP DELETE, the headers are getting stripped off coming into my database. Wether that is Apple's apache, or something else, I don't know. So, instead of sending the data to the url, with the form data attached, I would rather send the data as myurl.com/rest/table?id=123&whatever=true.

Currently my code has the ajax looking like this:

ajax: {
        edit: {
            type: 'PUT',
            "url": restURL + '/rest/Sales_Order_Line_Item',
            data: function ( d ) {
                delete d.action; //removing the default 'action=edit'
                d = d.data; //Moving everything up one level
                delete d.data; //deleting the data level
                return d;
            },
        },
        remove: {
            type: 'DELETE',
            "url": restURL + '/rest/Sales_Order_Line_Item',
            data: function ( d ) {
                return d;
            }
    }
}

I would like to maybe just append the values on the back of the url and just have no data, but I don't know how to access the current ID to do that. The edit works prefectly with the form data, but, like I said, the delete is having its data stripped when arriving at my database.

Any help would be greatly appreciated.

Thanks,
David Balderston

Answers

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    Hi David,

    It looks like form data in a DELETE is not something that is either explicitly allowed or disallowed in the HTTP spec, which I must admit I hadn't realised before. Let me look into this a little more and get back to you. I'd like to look into what jQuery does with the data for DELETE requests.

    Allan

  • CoreBioCoreBio Posts: 12Questions: 5Answers: 0

    Ok great, thank you very much Allan!

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    Hi,

    It looks like jQuery will allow the form data to be submitted, even although it would appear that the spec does specifically say:

    The DELETE method requests that the origin server delete the resource identified by the Request-URI.

    To my mind jQuery should therefore be using the query string in the same way as it does for GET requests - i.e. putting the data there. However, the spec doesn't explicitly disallow this action, and Apache does allow it.

    However, my own reading of the spec is that the query string should be used. So in Editor 1.5 it will automatically put the data on the query string, and not in the body. Editor 1.5.0 will be released shortly with this change.

    Thanks for bringing it up!

    Related reading:

  • CoreBioCoreBio Posts: 12Questions: 5Answers: 0

    Awesome, thank you Allen!! I'll keep an eye out for the new version :)

This discussion has been closed.