我有自动生成的id
service_type service_id
hair 1
skin 2
我有一个像这样的选择框
<label class="label-style">Service Type:</label>
<span><select id="service_type" name="service_type" class="form-control" required >
<option></option>
<option type="brillare">Brillare</option>
<option type="hair">Hair</option>
</select></span>
根据选择的服务类型需要更改service_id,例如
我需要在 laravel 中完成
service_type service_id
hair hr_1
skin sk_1
hair hr_2
skin sk_2
最佳答案
使用ajax方法: 如果您有另一个输入,其 id 为 service_id,则服务类型的 id 将显示在 service_id 输入中。
<script>
$(document).ready(function(){
$(document).on('change','#service_type',function(){
var service_id =$(this).val();
$.ajax({
type:'get',
url:'{!!URL::to('getserviceid')!!}',
data:{'type':service_id },
success:function(data){
$('#service_id').val(data);
},
error:function(){
}
});
});
});
</script>
我的 web.php:
Route::get('getserviceid','PageController@getserviceid');
页面 Controller :
public function getserviceid(Request $request)
{
$id = DB::table('services')->where('type', $request->type)->value('id');
return response()->json($id);
}
关于mysql - 需要自定义id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57886088/