In index controller your are returning a view wish is page you should just return $json or directly return $herbs
Jun 30, 2020
6
Level 1
I try to get some data, but I have all the pages code as response (AJAX)
Hello,
I'm trying to get data from a table to put them in a select list.
I have this JS code :
$.ajax
({
type: 'GET',
url: '../hinteractions/hdi',
dataType: 'json',
success: function(retour)
{
alert(retour);
alert("dans succes");
},
error:function(retour)
{
alert('dans erreur');
}
});
This is the controller :
public function index()
{
$herbs = Herb::all();
$json = json_encode($herbs);
return view('interaction.index', compact('herbs', 'json'));
}
I don't understand why I get as response the full page and not only my data ?
My response (only accepted if I put data : text) is something begining with this code :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Do you have any idea how can I get only $herbs ?
Thank you for your help.
Level 1
1 like
Please or to participate in this conversation.