1 week ago

I try to get some data, but I have all the pages code as response (AJAX)

Posted 1 week ago by dadub


I'm trying to get data from a table to put them in a select list.

I have this JS code :

        type: 'GET',
        url: '../hinteractions/hdi',
        dataType: 'json',
        success: function(retour)
            alert("dans succes");
            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>
  <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.

Please sign in or create an account to participate in this conversation.