Index: misc/drupal.js =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.js,v retrieving revision 1.1 diff -u -r1.1 drupal.js --- misc/drupal.js 24 May 2005 06:00:21 -0000 1.1 +++ misc/drupal.js 28 May 2005 13:19:43 -0000 @@ -60,6 +60,37 @@ } /** + * Creates an HTTP POST request and sends the response to the callback function + */ +function HTTPPost(uri, object, callbackFunction, callbackParameter) { + var xmlhttp = new XMLHttpRequest(); + var bAsync = true; + if (!callbackFunction) { + bAsync = false; + } + xmlhttp.open('POST', uri, bAsync); + xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + var formContents = ''; + for (var i in object) { + formContents += (formContents ? '&' : '') + i + '=' + escape(object[i]); + } + xmlhttp.send(formContents); + + if (bAsync) { + if (callbackFunction) { + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState == 4) { + callbackFunction(xmlhttp.responseText, xmlhttp, callbackParameter) + } + } + } + return true; + } else { + return xmlhttp.responseText; + } +} + +/** * Adds a function to the window onload event */ function addLoadEvent(func) {