Bob Ippolito wrote:
- That's all we (as in the sponsors/developers of MochiKit) need  right now
- The support for anything but GET and POST is poor cross-browser (this is largely Safari's fault) - There are at least three common ways to send POST data (url encoded, JSON, and XML) - It's often the case that you would also like to set custom headers when doing something other than GET

Well, I think there's at least one obvious implementation would be symmetric with doSimpleXMLHttpRequest, like:

function postSimpleXMLHttpRequest(url/*, ...*/) {
        var self = MochiKit.Async;
        var req = self.getXMLHttpRequest();
        var postBody = ''
        if (arguments.length > 1) {
postBody = m.queryString.apply(null, m.extend(null, arguments, 1));
        }
        req.open("POST", url, true);
        req.setRequestHeader(
            'Content-type', 'application/x-www-form-urlencoded');
        return self.sendXMLHttpRequest(req, postBody);
}

That's the only kind of non-GET request I've needed so far, and the only kind I expect to need for some time. I can imagine a JSON body, but I personally I don't need it, and I think a normal POST request is generally more likely to be useful.

While it didn't take me long to figure this out on my own, it also wasn't entirely obvious. I think this would cover 80% of all POST requests (and probably much more than that; it covers 100% of all the POSTs I've needed ;).

--
Ian Bicking  /  [EMAIL PROTECTED]  /  http://blog.ianbicking.org

Reply via email to