简体   繁体   English

我面临 500 内部服务器错误! 对于 ajax 代码

[英]i am facing 500 Internal server error! for a ajax code

I both a script for eCommerce website after install when I tried to edit any product it's throwing an error "500 Internal server error."安装后,当我尝试编辑任何产品时,我都是电子商务网站的脚本,它抛出错误“500 内部服务器错误”。 Then I traied to find out where is the problem.然后我试着找出问题出在哪里。 I found a tag that has some ajax and js code.我发现一个标签有一些 ajax 和 js 代码。 And that's the cause of the error.这就是错误的原因。

    enter code here
<script type="text/javascript">
    $(document).ready(function() {

        let html = `<img src="{{ empty($data->photo) ? asset('assets/images/noimage.png') : filter_var($data->photo, FILTER_VALIDATE_URL) ? $data->photo : asset('assets/images/products/'.$data->photo) }}" alt="">`;
        $(".span4.cropme").html(html);

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

    });


    $('.ok').on('click', function() {

        setTimeout(
            function() {


                var img = $('#feature_photo').val();

                $.ajax({
                    url: "{{route('admin-prod-upload-update',$data->id)}}",
                    type: "POST",
                    data: {
                        "image": img
                    },
                    success: function(data) {
                        if (data.status) {
                            $('#feature_photo').val(data.file_name);
                        }
                        if ((data.errors)) {
                            for (var error in data.errors) {
                                $.notify(data.errors[error], "danger");
                            }
                        }
                    }
                });

            }, 1000);



    });
</script>

How can I solve this problem please help me.我该如何解决这个问题,请帮助我。

There are many reasons for this problem.这个问题有很多原因。 Maybe you can try to check all below:也许您可以尝试检查以下所有内容:

  1. Check about csrf-token send with your ajax post.使用您的 ajax 帖子检查有关 csrf-token 发送的信息。 Try to add _token: $('meta[name="csrf-token"]').attr('content') into data send.尝试将 _token: $('meta[name="csrf-token"]').attr('content') 添加到数据发送中。
  2. Check about your route.检查您的路线。
  3. DataType return数据类型返回
  4. You need check about your server config.您需要检查您的服务器配置。 (htaccess, permission...) (htaccess,权限...)

You can view this post for more detail https://abbasharoon.me/how-to-fix-laravel-ajax-500-internal-server-error您可以查看此帖子以获取更多详细信息https://abbasharoon.me/how-to-fix-laravel-ajax-500-internal-server-error

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM