dadub
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

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.

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