I have a request that looks like this
var xhr = new XMLHttpRequest();
[...]
xhr.send("param1=" + obj.param1 + "¶m2=" + val);
I’d really prefer to write something like
xhr.send( {"param1": obj.param1, "param2": val} );
(A) Is it possible to do that?
(B) Where can I find a spec that would answer that question?
Not currently, but such things are included in the draft: http://www.w3.org/TR/XMLHttpRequest/#the-send-method. XmlHttpRequest should be able to send ArrayBuffers, Blobs, Documents, strings and FormData objects (examples at html5rocks).
However, sending objects is not supported – they’d need to be serializable. You could send them as a JSON string, or use one of the many library function to generate URL argument strings (like
jQuery.param()).I’ve linked the spec above, though for browser support you’d need to look at compatibility tables or the browsers’ documentations (eg. for FF at MDN).