diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-06-22 17:18:44 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-06-22 17:18:44 +0200 |
commit | c1f7615fa2a5dcc15fa3ed7962016537dd31bbfd (patch) | |
tree | c166ac80ff488e8706161a4defb373ee71e13bcd /lib/util.js | |
parent | 390f9042f82e4aaa6a57d08b9a5edfb38f688abf (diff) | |
download | bugzilla-triage-c1f7615fa2a5dcc15fa3ed7962016537dd31bbfd.tar.gz |
Make fixing MIME type again (includes creation of util.httpPOST)
- it is useful to have variable in the same module where the function using it
is.
- a lot of this magic and mystery
- add this.win property
- yuhooo, we have timer module, so I don't have to fish it from
this.doc.defaultView (which doesn't work anyway)
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/util.js b/lib/util.js index 02fd476..b165567 100644 --- a/lib/util.js +++ b/lib/util.js @@ -262,3 +262,38 @@ exports.loadJSON = function loadJSON(URL, cb_function, what) { cb_function.call(what, data); }, what); }; + +/** + * run HTTP POST request + * + * @param URL String with URL; required + * @param data Object/String with data ; required + * @param cb_function Function called when the request succeeds, with + * the only parameter being request object ; required + * @param what Object which will represent this for the cb_function ; optional + * @param mimeData String with MIME type of data + * @param mimeGet String with MIME type expected on return + */ +exports.httpPOST = function httpPOST(URL, data, cb_function, what, mimeData, mimeGet) { + what = what === undefined ? this : what; + mimeData = mimeData === undefined ? "application/x-www-form-urlencoded" : mimeData; + mimeGet = mimeGet === undefined ? "text/plain" : mimeGet; + + var req = new xhrMod.XMLHttpRequest(); + console.log("req = " + req.toSource()); + req.open("POST", URL, true); + + req.overrideMimeType(mimeGet); + req.setRequestHeader("Content-type", mimeData); + req.onreadystatechange = function(aEvt) { + if (req.readyState === 4) { + if (req.status === 200) { + console.log("POST success!"); + cb_function.call(what, req); + } else { + console.error("POST failed!"); + } + } + }; + req.send(data); +}; |