为什么会出现在Laravel框架这一内部服务器错误? [英] Why am I getting this Internal Server Error in the Laravel Framework?

查看:151
本文介绍了为什么会出现在Laravel框架这一内部服务器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也碰到过这种情况没有多大意义的我。正如一些背景信息,我使用了Laravel框架。有问题的页面调用时使用Laravel的请求的页面的查询 - 用>('变种',$阵列)语法。这个查询(我将在稍后发布)工作完全正常的页面加载,并成功地插入虚拟数据我喂它。

I have come across a situation that doesn't make much sense to me. Just as some background information, I'm using the Laravel framework. The page in question calls a query when the page is requested using Laravel's '->with('var', $array)' syntax. This query (which I will post later) works perfectly fine on page load, and successfully inserts dummy data I fed it.

我呼吁通过Ajax $此相同的查询。员额使用jQuery,在点击一个按钮。但是,当我这样做$。员额,并调用此查询,我得到一个内部服务器错误每次。一切正是通过包括相同的信息;唯一的区别似乎是是否它被称为上页面加载或通过$ .post的

I call this same query via an Ajax $.post using jQuery, on click of a button. However, when I do this $.post and call this query, I get an Internal Server Error every time. Everything is exactly the same, information passed included; the only difference seems to be whether or not it is called on page load or via the $.post.

下面是错误:

以下是code,其对网页加载查询:

routes.php文件发送HTTP GET请求到一个名为 AppController.php

routes.php sends the HTTP get request to a file called AppController.php

routes.php文件 AppController.php

routes.php AppController.php

页面,然后与 DeviceCheckoutController.php

,然后进入 DeviceCheckout.php

我能回声$测试在页面上,并且它的每一个页面重新加载时间(这显然意味着insertGetId查询工作)返回一个新行的ID。不过,我迷上此查询到的网页加载只是为了测试。我真的希望发生的是点击一个按钮。这里是code为:

I am able to echo $test on the page, and it returns the ID of a new row every time the page is reloaded (which obviously mean the 'insertGetId' query worked). However, I hooked this query up to the page load just to test. What I really want to happen is on click of a button. Here is the code for that:

$("#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部分:

Which is also then routed to AppController.php, specifically to the 'checkoutDeviceForStudent' part of the switch statement:

然后回所显示previously在 DeviceCheckout.php

And then back to that query that is shown previously in DeviceCheckout.php

最后,这里是我的数据库结构,以供参考:

Finally, here is my DB structure for reference:

任何解释为什么这会是这样吗?此外,任何Laravel或其他一般的最佳实践提示将大大AP preciated因为我没有经验在这个框架的使用情况和总体规划的。

Any explanation as for why this would be happening? Also, any Laravel or other general best practice tips would be greatly appreciated as I'm inexperienced in usage of this framework and programming overall.

对不起,这么长的帖子,我希望有足够的信息来诊断此问题。让我知道如果我需要包括其他任何东西。

Sorry for such a long post, I hope there is enough information to diagnose this problem. Let me know if I need to include anything else.

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

Included picture of error at the top of the page.

推荐答案

我发现了一个决议,经过一番咨询了一位朋友我的问题;比我预期的比已经提供给我在这里或其他地方的任何解决方案,更容易和更容易。

I found a resolution to my problem after some advice from a friend; much easier than I anticipated and much easier than any solution that has been offered to me here or other places.

从本质上讲,我需要做的是将尝试,渔获量子句在我的模型功能,然后如果有异常遇到我存储在一个变量,返回它,并使用的console.log()查看例外。下面是一个例子模仿我的观点:

Essentially, what I needed to do was place a try, catch clause in my model function, and then if an exception is encountered I store that in a variable, return it, and use console.log() to view the exception. Here is an example to emulate my point:

public function getUserFullname($userID)
{
    try
    {
        $myResult = DB::connection('myDatabase')->table('TheCoolestTable')->select('fullName')->where('userID', '=', $userID)->get();

        return $myResult;  
    }
    catch(Exception $e)
    {
        $errorMessage = 'Caught exception: ' . $e->getMessage();

        return $errorMessage;
    }
}

,然后在视图(或任何你的模型函数返回),简单地的console.log()您的帖子输出。这将显示成功查询结果,或异常的结果,如果它遇到的一个,而不是一个无用的内部服务器错误500消息。

And then on the View (or wherever your model function returns to), simply console.log() the output of your POST. This will display the results of the successful query, or the results of the Exception if it encountered one as opposed to an unhelpful Internal Server Error 500 message.

这篇关于为什么会出现在Laravel框架这一内部服务器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆