In some specific case I need to call function action again in itself. First time is working fine but second time meaning calling in itself doesn't work. I am using it in and calling from the form element with parameters.
function action(order, type) {
var xhttp;
var type = type;
var id;
var order = document.getElementById(order).innerText;
if (type != "start2") {
id = prompt("Načtěte svůj QR kód.");
}
if (id.trim() != null || id.trim() != "") {
xhttp = new XMLHttpRequest();
xhttp.open("POST", "functionSmallCustomers.php", true);
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var str = this.responseText;
if (str.trim() == '1') {
location.reload();
} else if (str.trim() == '2') {
var result = confirm("Opravdu chcete pikovat další zakázku? Jednu už máte rozpikovanou.");
if (result == true) {
action(order, "start2");
}
} else {
alert(str);
}
}
};
} else {
alert("Nenačetli jste QR kód.");
}
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("type=" + type + "&o=" + order + "&i=" + id);
}