I hava a problem with my ajax call and the json response. The console tell me that my php file don't return a json format but i don't understand why. Here is my ajax function :
function showEspece(espece, categorie, object)
{
$.ajax({
type : 'POST',
url: 'getespece.php',
data: {espece: espece, categorie: categorie },
dataType: 'json',
success: function(data)
{
alert(data);
var tableau = data;
$('#output').html(tableau);
},
error: function(xhr, status, error) {
console.log(xhr.responseText);
console.log(error);
}
});
}
And here is the php page call by the ajax function :
<?php
header('Content-type: application/json');
include("includes/connexionBD.php");
$requete = oci_parse($connect, "SELECT nomA, sexe, datenaissance FROM Animal WHERE categorie = '".$_POST['categorie']."' AND espece = '".$_POST['espece']."' ");
oci_execute($requete);
$test = oci_fetch_all($requete, $res);
$test1 = array();
$test1 = var_dump($res);
echo json_encode($test1);
?>
My problem is that the ajax function always go to error and here is what i can read in the console :
array(3) {
["NOMA"]=>
array(3) {
[0]=>
string(6) "Chachi"
[1]=>
string(6) "Rafiki"
[2]=>
string(6) "Chakra"
}
["SEXE"]=>
array(3) {
[0]=>
string(1) "F"
[1]=>
string(1) "M"
[2]=>
string(1) "F"
}
["DATENAISSANCE"]=>
array(3) {
[0]=>
string(9) "05-MAY-15"
[1]=>
string(9) "07-JAN-15"
[2]=>
string(9) "17-SEP-17"
}
}
null
SyntaxError: Unexpected token a in JSON at position 0
at parse (<anonymous>)
at Qb (jQuery.js:4)
at A (jQuery.js:4)
at XMLHttpRequest.<anonymous> (jQuery.js:4)
I have pass the day on it and i don't understand why it don't work. Can anyone help me ?