I want to run an Ajax query to get the "Datum" from the response "TesterID". Then I want to run the second Ajax with the previously received "Datum" to update with this value on another page, a DB entry.
Here is the code which doesn't work.
<script>
/* Funktionen um Startzeiten für Zyklen aus DB.TesterCycleCount zu erhalten bzw. für Test und Stunden, das aktuelle Datum gerundet auf 30 Minuten */
$(document).ready(function(){
var TesterID = "<?php echo $_GET['TesterID']; ?>"; /* value der Tester erhalten */
$.ajax({ /* AJAX aufrufen */
url: 'ma_get-TesterID_Testende.php',
type: 'get', /* Methode zum übertragen der Daten */
data: {TesterID:TesterID}, /* Daten zu übermitteln */
dataType: 'json',
success:function(response){ /* Die zurückgegebenene Daten erhalten */
var CID = response['CID'];
var Datum = response['Datum'];
},
error: function(jqxhtt, status, exception) {
alert('Exception:', exception)
}
}
var TestaufstellungID = "<?php echo $_GET['TestaufstellungID']; ?>";
$.ajax({ /* AJAX aufrufen */
url: 'ma_TestendeSQL.php',
type: 'get', /* Methode zum übertragen der Daten */
data: {Testaufstellung:TestaufstellungID, Datum: Datum}, /* Daten zu übermitteln */
dataType: 'json',
success:function(data){ /* Die zurückgegebenene Daten erhalten */
alert('Successfully called');
},
error: function(jqxhr, status, exception) {
alert('Exception:', exception)
}
}
});
</script>
This is the second PHP page, ma_TestendeSQL.php
, which doesn't update.
<?php
$cinfo = array(
"Database" => $database,
"UID" => $username,
"PWD" => $password
);
$conn = sqlsrv_connect($server, $cinfo);
$TestaufstellungID = $_GET['TestaufstellungID'];
$Datum = $_GET['Datum'];
$Testdatum = date('Y-d-m');
$stop = $conn->prepare("WITH UpdateTestende AS (
SELECT TOP 1 * from DB.dbo.Testergebnisse
WHERE TestaufstellungID = $TestaufstellungID
ORDER BY TestergebnisID DESC
)
update UpdateTestende
set Testende = '$Datum',
Datum = '$Testdatum'");
header('Content-type: application/json');
?>
The first Ajax works fine with the PHP page ma_get-TesterID_Testende.php
. I tested it already alone, but when I add the second Ajax try to update, the code I posted above doesn't work.
So the question: is it possible to run two Ajax like this?
Thanks.
Edit:
AJAX Call is empty or is not starting.
Further invstigation: The Ajax alert me the error part with empty exception and dont alert me the success part. So it doesnt go to the page ma_get-TesterID_Testende.php
or it doesnt return back the Datum
.
Could be not enabled Cross-Site-Scripting be the Problem?
But in another Page is a similiar Ajax Call working fine.
$(document).ready(function(){
var TesterID = "<?php echo $_GET['TesterID']; ?>"; /* value der Tester erhalten */
$.ajax({ /* AJAX aufrufen */
url: 'ma_get-TesterID.php',
type: 'get', /* Methode zum übertragen der Daten */
data: {TesterID:TesterID}, /* Daten zu übermitteln */
dataType: 'json',
success:function(response){ /* Die zurückgegebenene Daten erhalten */
var len = response.length;
$("#Teststart").empty(); /* Die erhaltenden Daten werden bei der ID angezeigt */
for( var i = 0; i<len; i++){
var CID = response[i]['CID'];
var Datum = response[i]['Datum'];
$("#Teststart").append("<option value='"+Datum+"'>"+Datum+"</option>");
}
}
});
$("#TesterID").change(function(){ /* Wenn du änderst und vom Select Feld auswählst */
var TesterID = $(this).val(); /* value der Tester erhalten */
$.ajax({ /* AJAX aufrufen */
url: 'ma_get-TesterID.php',
type: 'get', /* Methode zum übertragen der Daten */
data: {TesterID:TesterID}, /* Daten zu übermitteln */
dataType: 'json',
success:function(response){ /* Die zurückgegebenene Daten erhalten */
var len = response.length;
$("#Teststart").empty(); /* Die erhaltenden Daten werden bei der ID angezeigt */
for( var i = 0; i<len; i++){
var CID = response[i]['CID'];
var Datum = response[i]['Datum'];
$("#Teststart").append("<option value='"+Datum+"'>"+Datum+"</option>");
}
}
});
});
});
In this example the Ajax Call starts when i change the value from a Dropdown selection Form. Is there a difference?
How this Ajax should work i try to explain in my other question step by step, how it my application should be execute.
Update SQL Query with populated variables from AJAX functions over multiple PHP Pages
Edit 2: JQuery Version: https://code.jquery.com/jquery-3.4.1.js"