kompass/assets/ajax.js

26 lines
1.0 KiB
JavaScript

function kompass_generate_ajax_url(module, ajaxmethode, params) {
return ajaxurl + '?action=kompass_show_ajax&module=' + module + '&method=' + ajaxmethode + '&' + params;
}
function kompass_load_ajax_nw(module, ajaxmethode, params='') {
ajaxurl = kompass_generate_ajax_url(module, ajaxmethode, params);
window.open(ajaxurl);
}
function kompass_load_ajax_div(module, ajaxmethode, targetid, params = '') {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
// Erfolgreiche Antwort erhalten
document.getElementById(targetid).innerHTML = xhr.responseText;
} else {
console.log(xhr);
// Fehlerbehandlung
//console.error('Fehler beim Laden der Inhalte');
}
}
};
var scriptcall = kompass_generate_ajax_url(module, ajaxmethode, params);
xhr.open('GET', scriptcall,true);
xhr.send();
}