Home » Jquery » jquery – Unable to Print Json result in Laravel Blade

jquery – Unable to Print Json result in Laravel Blade

Posted by: admin February 22, 2020 Leave a comment

Questions:

I am trying to get result from controller to blade using ajax but it is showing undefined

Controller Code

function fetchDetail(Request $request){

        $iname=$request->get('iname');
        $data = add_items::select('*')
        ->where('item_name', 'LIKE', '%'.$iname.'%')
        ->get();

        return response()->json(['success'=>$data]);
    }

Blade Code

success:function(data){
                    console.log(data.item_name);
                                    console.log(data);
                                    var s=JSON.stringify(data);
                                    var s=JSON.parse(s);
                                    $.each(s,function(i,item){
                                        alert(item.item_name);
                                    });

                    //$('#countryList').html(data);
                  },

if I am printing data normally using

console.log(data);

showing properly, but the problem is with json result

How to&Answer: