I am not only new here, but also a total beginner in programming. I have programmed a small web application that uses "Ajax" to update data in the front panel. The first version works, but is very cumbersome and also takes a long time.
function updateAll(article){
document.getElementById("artnr").value = article.options[article.selectedIndex].text;
document.getElementById("SaveMessage").innerHTML = "";
// 1. Anzahl der Aufträge ermitteln
$.ajax({
type: 'GET',
url: 'cntOrder.php',
data: $(article),
success: function(data){document.getElementById("cntOrder").value = data;}
});
// 2. Median aller Uem-Werte
$.ajax({
type: 'GET',
url: 'setPoint.php',
data: $(article),
success: function(data){document.getElementById("setPoint").value = data; calcTarLim(data);}
}); // Aufruf 4. über "calcTarLim()"
// 3. Aktuelle Grenze auslesen
$.ajax({
type: 'GET',
url: 'curLim.php',
data: $(article),
success: function(data){document.getElementById("curLim").value = data;}
});
// 5. Graph aktualisieren (Messwerte, currentLimit und targetLimit)
}
// 4. Zielwert für Grenze berechnen
function calcTarLim(data){
let tol = parseFloat(document.getElementById("tolLim").value);
let soll = 0;
if(data == 'change'){
window.alert("if: " + data);
} else {
soll = parseFloat(data);
}
let ziel = soll * ((100-tol)/100);
ziel = ziel.toFixed(2);
document.getElementById("tarLim").value = ziel;
}
Now my idea was to handle all queries in one Ajax query and put the different return values in an array and then evaluate them using the keys. Unfortunately I don't get any values out.
function updateAll(article){
document.getElementById("artnr").value = article.options[article.selectedIndex].text;
document.getElementById("SaveMessage").innerHTML = "";
// 1. Ajax Aufruf, Datenbankfunktionen
$.ajax({
type: 'GET',
url: 'ajax.php',
data: $(article),
success: function(data){
window.alert(data);
document.getElementById("cntOrder").value = data['cntOrder']['cnt'];
document.getElementById("setPoint").value = data['setPoint'];
document.getElementById("curLim").value = data['CurLim']['uemmin'];
calcTarLim(data['setPoint']);
}
});
Data looks like this:
Array
(
[cntOrder] => Array
(
[cnt] => 6
)
[curLim] => Array
(
[uemmin] => 16.00
)
[setPoint] => 26.28
)
Thanks in advance for any help. If more data is needed, I will of course add it.
dataType: "json",in the ajax and return the array asjson_encode($array). stackoverflow.com/questions/7064391/…{"cntOrder":{"cnt":"6"},"curLim":{"uemmin":"16.00"},"setPoint":"26.28"}but I still have no access to the individual keys. I will look further how to access it, if it is a json. thanks anyway.dataType: "json",into your ajax request and it should workphp, includeheader("Content-Type: application/json"); echo json_encode($yourArray);