lundi 17 février 2020

Unable to Print Json result in Laravel Blade

i'm trying to getting result from controller to blade using ajax but it 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'm printing data normally using

console.log(data);

showing properly, but the problem is with json result



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire