Skip to content
Snippets Groups Projects
Commit 9f67ddf9 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #23746 by Thox: added support for Ajax HTTPPost functionality.

parent e0158075
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -23,16 +23,16 @@ if (isJsEnabled()) { ...@@ -23,16 +23,16 @@ if (isJsEnabled()) {
* Make IE's XMLHTTP object accessible through XMLHttpRequest() * Make IE's XMLHTTP object accessible through XMLHttpRequest()
*/ */
if (typeof XMLHttpRequest == 'undefined') { if (typeof XMLHttpRequest == 'undefined') {
XMLHttpRequest = function () { XMLHttpRequest = function () {
var msxmls = ['MSXML3', 'MSXML2', 'Microsoft'] var msxmls = ['MSXML3', 'MSXML2', 'Microsoft']
for (var i=0; i < msxmls.length; i++) { for (var i=0; i < msxmls.length; i++) {
try { try {
return new ActiveXObject(msxmls[i]+'.XMLHTTP') return new ActiveXObject(msxmls[i]+'.XMLHTTP')
} }
catch (e) { } catch (e) { }
} }
throw new Error("No XML component installed!") throw new Error("No XML component installed!")
} }
} }
/** /**
...@@ -41,16 +41,55 @@ if (typeof XMLHttpRequest == 'undefined') { ...@@ -41,16 +41,55 @@ if (typeof XMLHttpRequest == 'undefined') {
function HTTPGet(uri, callbackFunction, callbackParameter) { function HTTPGet(uri, callbackFunction, callbackParameter) {
var xmlHttp = new XMLHttpRequest(); var xmlHttp = new XMLHttpRequest();
var bAsync = true; var bAsync = true;
if (!callbackFunction) if (!callbackFunction) {
bAsync = false; bAsync = false;
}
xmlHttp.open('GET', uri, bAsync); xmlHttp.open('GET', uri, bAsync);
xmlHttp.send(null); xmlHttp.send(null);
if (bAsync) { if (bAsync) {
if (callbackFunction) { if (callbackFunction) {
xmlHttp.onreadystatechange = function() { xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) if (xmlHttp.readyState == 4) {
callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter) callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
}
}
}
return true;
}
else {
return xmlHttp.responseText;
}
}
/**
* 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);
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 (callbackFunction) {
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
}
} }
} }
return true; return true;
...@@ -163,4 +202,4 @@ function removeNode(node) { ...@@ -163,4 +202,4 @@ function removeNode(node) {
else { else {
return false; return false;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment