为什么在使用laravel ajax发送到控制器时id为null
我在annonces表中有多个图像,我想更新多个图像,我只想将数据(id、图像、令牌)发送到控制器,但它为id提供了为什么在使用laravel ajax发送到控制器时id为null,ajax,laravel,Ajax,Laravel,我在annonces表中有多个图像,我想更新多个图像,我只想将数据(id、图像、令牌)发送到控制器,但它为id提供了null details.blade.php <h3 class="jumbotron" id="id">{{ $annonces->id }}</h3> <h3 class="jumbotron">ajouter les images produit</h3> <
null
details.blade.php
<h3 class="jumbotron" id="id">{{ $annonces->id }}</h3>
<h3 class="jumbotron">ajouter les images produit</h3>
<form method="post" action="{{route('filesUpdate')}}" enctype="multipart/form-data" class="dropzone" id="dropzone">
<!--<input type="hidden" name="_method" value="PUT">-->
{{ csrf_field() }}
</form>
<script type="text/javascript">
var id = $("#id").val();
Dropzone.options.dropzone =
{
console.log(id);
maxFilesize: 12,
renameFile: function(file) {
images = file.name;
$.ajax({
url:"{{ route('filesUpdate') }}" ,
type:'POST',
data:{
id : id,
"_token": "{{ csrf_token() }}"
},
success: function(file, response)
{
console.log(response);
},
error: function(file, response)
{
return false;
}
})
//return images;
},
acceptedFiles: ".jpeg,.jpg,.png,.gif",
addRemoveLinks: true,
timeout: 50000,
success: function(file, response)
{
console.log(response);
},
error: function(file, response)
{
return false;
}
};
</script>
public function filesUpdate(Request $request)
{
dd($request->id);
}
取代
var id=$(“#id”).val();//当元素是输入时使用的val()方法。
到
var id=$(“#id”).html();