This ajax request send two parameters x and y to a php controller :
$.ajax({
url : 'feuilles/test',
data: {
x: x, y: y
},
type : 'post',
dataType : 'json',
success : function(res){
$.each(res, function(index, element) {
alert("index "+index + " element "+element);
});
},
error : function(result, statut, erreur){
console.log(result);
},
complete : function(resultat, statut){
//"completed"
}
});
here's is the php controller :
public function test(){
$x = $this->request->data['x'];
$y = $this->request->data['y'];
$actualFeuille = $this->request->session()->read('actualFeuille');
$res = $actualFeuille->getListOfPossibilies(0,2);
$this->set('res', $res);
}
$res get an array here's its content :
[
(int) 0 => (int) 1,
(int) 1 => (int) 2,
(int) 2 => (int) 3,
(int) 3 => (int) 4,
(int) 4 => (int) 5,
(int) 5 => (int) 6,
(int) 6 => (int) 7,
(int) 7 => (int) 8,
(int) 8 => (int) 9,
(int) 9 => (int) 10,
(int) 10 => (int) 11,
(int) 11 => (int) 12,
(int) 12 => (int) 13,
(int) 13 => (int) 14
]
When I get back the response it shows that there's an error, the fact is that the body recieved in the response html content just like the following example :
"<div class="cake-debug-output"> <span><strong>\src\Model\Entity\Feuille.php</strong> (line <strong>68</strong>)</span> <pre class="cake-debug"> (int) 15 </pre> </div><div class="cake-debug-output"> <span><strong>\src\Model\Entity\Feuille.php</strong> (line <strong>61</strong>)</span> <pre class="cake-debug"> [ (int) 0 => (int) 1, (int) 1 => (int) 2, (int) 2 => (int) 3, (int) 3 => (int) 4, (int) 4 => (int) 5, (int) 5 => (int) 6, (int) 6 => (int) 7, (int) 7 => (int) 8, (int) 8 => (int) 9, (int) 9 => (int) 10, (int) 10 => (int) 11, (int) 11 => (int) 12, (int) 12 => (int) 13, (int) 13 => (int) 14 ] </pre> </div>{ "res": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ] }"
We can see that the body got the array in it but because of the html contained in the body it displays an error. My question is what to do to only get the array in the body of the response and remove all the useless html.