<script>
$('#brand_id').on('change',function(e){
console.log(e);
var brand_id = e.target.value;
//ajax
$.get('/product_id?brand_id =' + brand_id, function(data));
//success data
$.each(data, function(upload_form, product_cat){
$('product_category').empty();
$('product_category').append('<option value="'+ product_cat.id +'">'+ product_cat.product_hierarchy +'</option>');
});
});
Above is my Jquery code check this and point out me what is the problem.
<form enctype="multipart/form-data" action="{{action('BrandController@upload_csv')}}" method="post">
Brand Code
<select name="brand_id" id="brand_id" Select="" class="form-control">
<option value="">--Select Brand Code--</option>
<?php foreach ($brands as $row) { ?>
<option value="<?= $row->brand_id ?>"><?= $row->brand_name ?></option>
<?php } ?>
</select>
Product Id
<select name="product_category" id="product_category" Select="" class="form-control">
</select>
Status
<select name="status" Select="" class="form-control">
<option value="">--Select Product Status--</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<input type="hidden" name="_token" value="<?= csrf_token(); ?>">
Upload Valid csv file
<input type="file" name="csv" required class="form-control">
<br/>
<input type="submit" value="Upload" class="btn btn-primary">
</form>
This is my form. in the form there is a select in which onchange element i want to show sub categories in next select. Below is my Route file code.
Route::get('/product_id', function(){ $brand_id = Input::get('brand_id');
$product_id = product_hierarchy::where('bcategory_code','=',1)->get();
return Response::json($product_id);
});
<script>
$('#brand_id').on('change',function(e){
console.log(e);
var brand_id = e.target.value;
//ajax
$.get('/product_id?brand_id =' + brand_id, function(data));
//success data
$.each(data, function(upload_form, product_cat){
$('product_category').empty();
$('product_category').append('<option value="'+ product_cat.id +'">'+ product_cat.product_hierarchy +'</option>');
});
});
Above is my Jquery code check this and point out me what is the problem.
<form enctype="multipart/form-data" action="{{action('BrandController@upload_csv')}}" method="post">
Brand Code
<select name="brand_id" id="brand_id" Select="" class="form-control">
<option value="">--Select Brand Code--</option>
<?php foreach ($brands as $row) { ?>
<option value="<?= $row->brand_id ?>"><?= $row->brand_name ?></option>
<?php } ?>
</select>
Product Id
<select name="product_category" id="product_category" Select="" class="form-control">
</select>
Status
<select name="status" Select="" class="form-control">
<option value="">--Select Product Status--</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<input type="hidden" name="_token" value="<?= csrf_token(); ?>">
Upload Valid csv file
<input type="file" name="csv" required class="form-control">
<br/>
<input type="submit" value="Upload" class="btn btn-primary">
</form>
This is my form. in the form there is a select in which onchange element i want to show sub categories in next select. Below is my Route file code.
Route::get('/product_id', function(){ $brand_id = Input::get('brand_id');
$product_id = product_hierarchy::where('bcategory_code','=',1)->get();
return Response::json($product_id);
});
Share Improve this question asked May 23, 2016 at 7:40 Ayaz khanAyaz khan 1531 gold badge5 silver badges17 bronze badges 2- What's the problem ? Which version of laravel you are using ? – Kalpesh Rajai Commented May 23, 2016 at 7:46
- laravel 5.2 Jquery not working will – Ayaz khan Commented May 23, 2016 at 8:29
1 Answer
Reset to default 2In Laravel 5.2
we have to pass the csrf
token to execute the request.
just try like this...
<script>
$('#brand_id').on('change',function(e){
console.log(e);
var brand_id = e.target.value;
//ajax
$.get('/product_id?brand_id =' + brand_id,{"_token":$("input[name='_token']").val()}, function(data));
//success data
$.each(data, function(upload_form, product_cat){
$('product_category').empty();
$('product_category').append('<option value="'+ product_cat.id +'">'+ product_cat.product_hierarchy +'</option>');
});
});
</script>
I just add this line of code to your get request:
{ "_token" : $("input[name='_token']").val() }
Good Luck.. Happy Coding!!!
Edited
For detailed information about this you can found on the below linked tutorials:
Laravel CRUD Using jQuery AJAX PART – 1
Laravel CRUD Using jQuery AJAX PART – 2
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745570362a4633645.html
评论列表(0条)