javascript - 为什么我在 Laravel 框架中收到此内部服务器错误?

标签 javascript php jquery ajax laravel

我遇到了一种对我来说没有多大意义的情况。正如一些背景信息一样,我正在使用 Laravel 框架。当使用 Laravel 的 '->with('var', $array)' 语法请求页面时,相关页面会调用查询。这个查询(我将在稍后发布)在页面加载时工作得非常好,并成功插入我提供的虚拟数据。

我通过 Ajax $.post 使用 jQuery 单击按钮来调用相同的查询。但是,当我执行此 $.post 并调用此查询时,每次都会收到内部服务器错误。一切都一模一样,包括传递的信息;唯一的区别似乎是它是在页面加载时调用还是通过 $.post 调用。

这是错误:

enter image description here

下面是在页面加载时执行查询的代码:

routes.php 将 HTTP get 请求发送到名为 AppController.php

的文件

routes.php enter image description here AppController.php enter image description here

然后使用从 DeviceCheckoutController.php 获取的以下数组创建页面

enter image description here

然后转到DeviceCheckout.php

enter image description here

我能够在页面上回显 $test,并且每次重新加载页面时它都会返回新行的 ID(这显然意味着“insertGetId”查询有效)。但是,我将此查询连接到页面加载只是为了测试。我真正想要发生的是单击按钮。这是代码:

$("#checkoutFormbox").on('click', '#checkoutButton', function() {

        var checkoutInformation = Object();
        var accessories = [];
        var counter = 0;
        var deviceName = checkoutDeviceTable.cell(0, 0).data();

        $(".accessoryCheckbox").each(function() {
            //add accessory ID's to this list of only accessories selected to be checked out
            if($(this).val() == "1")
            {
                accessories[counter] = $(this).data('id') + " ";
            }
            counter++;
        });

        checkoutInformation['deviceID'] = $(".removeButton").val(); //deviceID was previously stored in the remove button's value when the add button was clicked
        checkoutInformation['outBy'] = '';
        checkoutInformation['outNotes'] = $("#checkOutDeviceNotes").val();
        checkoutInformation['idOfAccessories'] = 2;
        checkoutInformation['dueDate'] = $("#dueDate").val();

        if($("#studentIdButton").hasClass('active'))
        {
            checkoutInformation['renterID'] = 0;
            checkoutInformation['emplid'] = 1778884;
            console.log(checkoutInformation);
            $.post("http://xxx.xxx.xxx.xxx/testing/public/apps/devicecheckout-checkoutdevices", {type: "checkoutDeviceForStudent", checkoutInformation: checkoutInformation}, function(returnedData) {
                alert(returnedData);
            });
        }
});

然后也会路由到 AppController.php,特别是 switch 语句的“checkoutDeviceForStudent”部分:

enter image description here

然后返回到之前在 DeviceCheckout.php 中显示的查询

最后,这是我的数据库结构供引用:

enter image description here

有什么解释为什么会发生这种情况吗?此外,任何 Laravel 或其他一般最佳实践技巧将不胜感激,因为我在使用此框架和整体编程方面缺乏经验。

很抱歉这篇文章很长,我希望有足够的信息来诊断这个问题。如果我需要添加其他内容,请告诉我。

编辑:在页面顶部包含错误图片。

最佳答案

Everything is exactly the same, information passed included

不,不是。如果它完全相同,您就不会收到您所收到的错误。

这类问题很难通过猜测问题所在来解决。你需要

  1. 设置您的系统,以便 Laravel 将错误记录到 laravel.log 文件

  2. 设置 PHP 系统,以便将 Laravel 无法处理的错误记录到网络服务器的错误日志(和/或 PHP 的错误日志)中

  3. 将 Laravel 置于 Debug模式,以便将错误输出到屏幕上,并通过 Firebug 或 Chrome 查看 ajax 请求的输出

一旦出现实际的 PHP 错误,通常很容易看出您认为相同的请求有什么不同,并解决问题。

关于javascript - 为什么我在 Laravel 框架中收到此内部服务器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25489011/

相关文章:

eval 反序列化后 Javascript 原型(prototype)未定义

php - 不支持的 SSL 请求 - Php artisan serve

javascript - 当它从底部显示 100px 时如何在滚动上触发 jquery 函数

javascript - 动态 jQuery 变量名

javascript - AWS S3 - 凭据在代码中公开

javascript - 如何使用 jQuery 更改 anchor 的 `href` 属性

php - 谷歌图表实时更新ajax

javascript - InnerHtml 更改后鼠标无法工作

javascript - 为什么我的航路点添加类在向下滚动时没有删除

javascript - 如何为 wordpress 创建一个像 SMINT 这样的粘性导航?