armancs's avatar

Not found jason data

I have two table as like country and school. so now what i am gonna do that, in school there is a country_id as fk.now when i select country all country appear but not showing schools under that id.

controller: query for getting school.

$countries      = Input::get('ref_country_id');
    $schoolList     = LanguageSchoolModel::where('ref_country_id','=',$countries)->get();
    return response()->json($schoolList);

Route:

Route::get('json-school','Adminpanel\school@lng_school_list');

JS for dependent dropdown:

$(document).ready(function(){
     $('#countries').on('change',function(e){
        console.log(e);
        var country_id  = e.target.value;
        $.get('json-school?country_id=' +country_id,function(data){
            console.log(data);
            var option='<option value="0" disable="true" selected="true">Select city</option>';
            $.each(data, function( index, schoolObj){
               option+='<option value="'+schoolObj.id+'" >'+schoolObj.name+'</option>';
            })
            $('#schoolList').html(option);
             $('#schoolList').selectpicker('refresh');
        })

    })

 })

Nothing found when access this : json-school?country_id=2

0 likes
3 replies
Procat's avatar

I think you have a typo, ref_country_id vs country_id.

mcardosob's avatar

What appends when your try to access to the "json-school" url with your browser.

Try this and don't forget to pass a get parameter.

Bruno MC

armancs's avatar

@Procat here country_id is variable and ref_country_id is field name in db. @mcardosob in json-school empty value showing. :(

Please or to participate in this conversation.