dimanche 10 juillet 2016

laravel5.1 , pls help me , value not send to second drop down list

pls help me , value not send to second drop down list

first dropdown list can get data from database

in second dropdown dont hav anythink return to this

how to resolve its , i'm new for programming

ProvinceController.php

    <?php
    namespace App\Http\Controllers;
    use App\Model\Province;
    use App\Model\Bras;
    use Illuminate\Http\Request;
    use View;
    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    use DB;
    use Illuminate\Support\Facades\Input;

    class ProvinceController extends Controller
    {

        public function province(){
          $dataProvince = Province::all();
           $rowsProvince = array();
           $rowsProvince[''] = 'select province';
           foreach ($dataProvince as $rowProvince) {
               $rowsProvince[$rowProvince->provinceid] = $rowProvince->nameprovince;
           }
           return View::make('index')->with('rowsProvince', $rowsProvince);
        }
    }


route.php 


Route::get('/Province', 'ProvinceController@province');
Route::get('/Province/bras', function(){

$provinceid = Input::get('provinceid');
$bras  = DB::table('bras')->select('brasid','brasname')-   >where('provinceid','=',$provinceid)->get();
return Response::json($bras);
});

index.blade.php

<html>
<div class="container">
    <h2>test</h2>
    <div>
      
          <div class="form-group">
              
              
         </div>
         <div class="form-group">
            
            
         </div>
      
    </div>
</div>
</html>

my script>

$('#provinceid').on('change', function(e){
  console.log(e);
    var provinceid = e.target.value;
       //ajax
       $.getJSON('/Province/bras?provinceid=' + provinceid , function(data){
           //success data
           console.log(data);
           var bras = $('#brasid');
           bras.empty();
           $.each(data, function(index, brasObj){

               bras.append("option value='" +brasObj.id+ "'>"+brasObj.name+"</option>");
           });
       });
   });

browser show



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire