Json 如何在没有发送按钮的情况下从表单上载图像,并在Laravel中上载后自动刷新?

Json 如何在没有发送按钮的情况下从表单上载图像,并在Laravel中上载后自动刷新?,json,ajax,laravel,forms,submit,Json,Ajax,Laravel,Forms,Submit,我尝试了在互联网上找到的所有变体,但没有结果 web.php的路径:route::post('profile','UserController@update_avatar'); profile.blade.php的格式: <form id="avatar-form" enctype="multipart/form-data" action="/profile" method="POST"> <label>Update Profile Image</label&g

我尝试了在互联网上找到的所有变体,但没有结果

web.php的路径:
route::post('profile','UserController@update_avatar');

profile.blade.php的格式:

<form id="avatar-form" enctype="multipart/form-data" action="/profile" method="POST">
  <label>Update Profile Image</label>
  <input type="hidden" name="name" value="{{ $user->name }}">
  <input type="file" name="avatar" id="avatar">
  <input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
出现问题的脚本..:

<script>
        $("#avatar").click(function(){
            $.ajax({
                type: "POST",
                data: $('#avatar-form').serialize(),
                url: "<?php echo url('/profile') ?>",
                success:function(data){
                    console.log(data);
                },

            });
        });
    </script>

$(“#化身”)。单击(函数(){
$.ajax({
类型:“POST”,
数据:$('#化身形式')。序列化(),
url:“”,
成功:功能(数据){
控制台日志(数据);
},
});
});

只需创建一个
更改
事件:

<script>
        $("#avatar").change(function(){
            $.ajax({
                type: "POST",
                data: $('#avatar-form').serialize(),
                url: "<?php echo url('/profile') ?>",
                success:function(data){
                    window.location.href = window.location.href;
                },

            });
        });
    </script>

$(“#化身”).change(函数(){
$.ajax({
类型:“POST”,
数据:$('#化身形式')。序列化(),
url:“”,
成功:功能(数据){
window.location.href=window.location.href;
},
});
});

他不想这样。但是脚本中的“url”还行吗?@iliseCristian echo url('/profile')对你有什么好处?我真的不知道,我是在网络上的一个教程之后编写的脚本将此作为第一个操作放入脚本中:警报(“”),让我知道你看到了什么好吧,上传图片时什么都没有发生,仅显示上传图片的名称,依此类推
<script>
        $("#avatar").change(function(){
            $.ajax({
                type: "POST",
                data: $('#avatar-form').serialize(),
                url: "<?php echo url('/profile') ?>",
                success:function(data){
                    window.location.href = window.location.href;
                },

            });
        });
    </script>