Ajax Function Working On Local But Not Online
Here is my problem, I have a AJAX function which is working on my local server but don't return anything when I put it on my online server. Here is my code : Here the page where I
Solution 1:
The issue here is that your JSON response is malformed, you could try getting the output JSON and put it through a linter to find where the problem actually is:
I would recommend not building the HTML (your table) in PHP but building it using Javascript and injecting the data from the Ajax request into the table.
Solution 2:
Change php response code with the following,
<?phpinclude("/includes/connexionBD.php");
include("includes/entetepage.php");
$requete = oci_parse($connect, "SELECT nomA, sexe, datenaissance FROM Animal WHERE categorie = '".$_POST['categorie']."' AND espece = '".$_POST['espece']."' ");
oci_execute($requete);
$table = "<table>\n";
$table .= "<thead>\n";
$table .= "<td><b> Nom </b></td>\n";
$table .= "<td><b> Sexe </b></td>\n";
$table .= "<td><b> Date naissance </b></td>\n";
$table .= "</thead>\n";
while ($row = oci_fetch_array($requete, OCI_ASSOC+OCI_RETURN_NULLS)) {
$table .= "<tr>\n";
foreach ($rowas$item) {
$table .= " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "") . "</td>\n";
}
$table .= "</tr>\n";
}
$table .= "</table>\n\n";
echo json_encode(array("table"=>$table, JSON_UNESCAPED_SLASHES));
?>
change ajax code with the following
functionshowEspece(espece, categorie, object)
{
$.ajax({
type : 'POST',
url: 'getespece.php',
data: {espece: espece, categorie: categorie },
dataType: 'json',
success: function(data)
{
alert('ok');
var tbl = $.parseJSON(data);
var tableau = tbl.table;
console.log(tableau);
$('#output').html(tableau);
},
error: function(xhr, status, error) {
console.log(xhr);
}
});
}
Post a Comment for "Ajax Function Working On Local But Not Online"