微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Laravel 8 中发送“Ajax 请求”时没有返回值

如何解决在 Laravel 8 中发送“Ajax 请求”时没有返回值

我在laravel 8中使用“java脚本”发送请求ajax:(XMLHttpRequest对象)

enter code here
请求数据

错误

<script>
    function loadDoc() {
        var response;
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                // document.getElementById("err").innerHTML = this.responseText;

                console.log(response.success);

            }
        };
        xhttp.open("GET","rout5",true);
        xhttp.send();

    }
</script>

路线:

Route::get('rout5',[AjaxController::class,'AjaxController']);

控制器: 公共函数 AjaxController(){

return response()->json(['success' => 'hello world']);

}

发送请求时,在选项卡网络(浏览器)中我得到代码 200 但在选项卡控制台中,我收到此错误: 响应未定义。 什么问题?谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。