Index: misc/drupal.js =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.js,v retrieving revision 1.3 diff -u -r1.3 drupal.js --- misc/drupal.js 21 Jun 2005 09:45:43 -0000 1.3 +++ misc/drupal.js 15 Jul 2005 09:27:15 -0000 @@ -61,6 +61,38 @@ } /** + * Creates an HTTP POST request and sends the response to the callback function + */ +function HTTPPost(uri, object, callback_function, callback_parameter) { + var xmlhttp = new XMLHttpRequest(); + var bAsync = true; + if (!callback_function) + bAsync = false; + xmlhttp.open('POST', uri, bAsync); + + var toSend = ''; + if (typeof object == 'object') { + xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + for (var i in object) + toSend += (toSend ? '&' : '') + i + '=' + escape(object[i]); + } + else { + toSend = object; + } + xmlhttp.send(toSend); + + if (bAsync) { + if (callback_function) + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState == 4) + callback_function(xmlhttp.responseText, xmlhttp, callback_parameter) + } + return true; + } else + return xmlhttp.responseText; +} + +/** * Adds a function to the window onload event */ function addLoadEvent(func) {