mercredi 28 juin 2017

i am not able to display my state name and city name using drop down in laravel

                This is my playingcards-advance ie view page

             <h5>Country:</h5>
                                      <select class="productcategory put" id="prod_cat_id">

                    <option value="0" disabled="true" selected="true">-Select-</option>
                    @foreach($prod as $cat)
                        <option value=""></option>
                    @endforeach

                </select>
                                      <h5>State:</h5>
                                    <select class="productname put">

                    <option value="0" disabled="true" selected="true">Select State</option>
                </select>
                 <h5>City:</h5>
                                         <select  class="city put">

                    <option value="0" disabled="true" selected="true">Select City</option>
                </select>

                <script src="http://ift.tt/2eBd7UN"></script>

                <script type="text/javascript">
                    $(document).ready(function(){

                        $(document).on('change','.productcategory',function(){
                            // console.log("hmm its change");

                            var cat_id=$(this).val();
                            // console.log(cat_id);
                            var div=$(this).parent();

                            var op=" ";

                            $.ajax({
                                type:'get',
                                url:'{!!URL::to('findProductName')!!}',
                                data:{'id':cat_id},
                                success:function(data){
                                    //console.log('success');

                                    //console.log(data);

                                    //console.log(data.length);
                                    op+='<option value="0" selected disabled>Select City</option>';
                                    for(var i=0;i<data.length;i++){
                                    op+='<option value="'+data[i].id+'">'+data[i].productname+'</option>';
                                   }

                                   div.find('.productname').html(" ");
                                   div.find('.productname').append(op);
                                },
                                error:function(){

                                }
                            });
                        });

                        $(document).on('change','.productname',function () {
                            var prod_id=$(this).val();

                            var a=$(this).parent();
                            console.log(prod_id);
                            var op="";
                            $.ajax({
                                type:'get',
                                url:'{!!URL::to('findcity')!!}',
                                data:{'id':prod_id},
                                dataType:'json',//return data will be json
                                success:function(data){
                                     console.log('success');

                                    console.log(data);
                              op+='<option value="0" selected disabled>choose city</option>';
                                    for(var i=0;i<data.length;i++){
                                    op+='<option value="'+data[i].id+'">'+data[i].city+'</option>';
                                   }

                 a.find('.city').html(" ");
                                   a.find('.city').append(op);





                                },
                                error:function(){

                                }
                            });


                        });

                    });
                </script>
  This is my Route code 
        Route::get('/playingcards-advance','PagesController@prodfunct');
        Route::get('/findProductName','PagesController@findProductName');
        Route::get('/findPrice','PagesController@findPrice');
        Route::get('/findcity','PagesController@findcity');




        This is PagesController code 
         public function prodfunct(){

                $prod=ProductCat::all();//get data from table
                return view('playingcards-advance',compact('prod'));//sent data to view

            }

            public function findProductName(Request $request){


                //if our chosen id and products table prod_cat_id col match the get first 100 data 

                //$request->id here is the id of our chosen option id
                $data=Product::select('productname','id')->where('prod_cat_id',$request->id)->take(100)->get();
                return response()->json($data);//then sent this data to ajax success
            }

           public function findcity(Request $request){


                //if our chosen id and products table prod_cat_id col match the get first 100 data 

                //$request->id here is the id of our chosen option id
                $q=City::select('city','id')->where('state_id',$request->id)->take(100)->get();
                return response()->json($q);//then sent this data to ajax success
            }



    The problem is that i m not able to display state and city but i m able to display country
    i have also made model of all table 
    why it is not displayng state and city in the code 
   when i click on console and try to select country as America it is giving this error GET http://localhost/tmcards2/public/findProductName?id=1 500 (Internal Server Error)

    The problem is that i m not able to display state and city but i m able to display country
    i have also made model of all table 
    why it is not displayng state and city in the code 
   when i click on console and try to select country as America it is giving this error GET http://localhost/tmcards2/public/findProductName?id=1 500 (Internal Server Error)

The problem is that i m not able to display state and city but i m able to display country i have also made model of all table why it is not displayng state and city in the code when i click on console and try to select country as America it is giving this error GET http://localhost/tmcards2/public/findProductName?id=1 500 (Internal Server Error)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire