Can anyone see a problem with this? It was working but now ‘genitive’ comes back as undefined and the url doees not seem to be getting executed. The call is passed the ID of a constellation for example 42 = Hydra, the call should return the genitive which is Hydrae.
function updateSN(ev) {
ev.preventDefault();
var e = document.getElementById("frm_GreekID");
var gid = e.value;
var text = e.options[e.selectedIndex].text;
var cons = document.getElementById("frm_Constellation");
var ctxt = cons.value;
alert("CVAL = " + ctxt);
$.ajax({
url: "ggenitive.php",
type: "POST",
data: {
c: ctxt,
},
success: function (response) {
// show response for success
let genitive = response.value;
alert("GENITIVE = " + genitive);
document.getElementById("frm_StarName").value = gid + " " + genitive;
},
});
}
in the ggenitive.php page I get the correct response when changing the $_POST to $_GET and passing the constellation value in the url, i know the function is getting called because the alert boxes work.
Here is the ggenitive.php if this helps
<?php
require( '../db_connect.php' );
include( '../inc/tvms_inc.php' );
//var_dump($_POST);
session_start();
$qga = "SELECT cGenitive FROM `ast_cons` WHERE id = '".$_POST['c']."'";
$rga = mysqli_query( $conn, $qga )or die( "<div class='container'><table class='table'><tr><th>COULD NOT PERFORM QUERY [GENITIVE]</th></tr><tr><td>" . $qga . "</td><tr>" . mysqli_error( $conn ) . "</td></tr></table></div>" );
$row=mysqli_fetch_assoc($rga);
echo $row['cGenitive'];
?>
2
Answers
Your response is a plain string which does not have a
value
property.You can just use the plain string response directly
I would also recommend using some modern practices for your server-side code. Namely using prepared statements and responding with appropriate status codes in case of errors
Try this change and see if it addresses the problem. The response variable should directly hold the server’s response data. If you continue to have issues, consider logging the server’s real answer to the console: