[英]Why am i getting 500 (Internal Server Error) when settting new src for iframe dynamically?
[英]Why am I getting this Internal Server Error in the Laravel Framework?
我遇到的情况对我来说没有太大意义。 就像一些背景信息一样,我正在使用Laravel框架。 当使用Laravel的'-> with('var',$ array)'语法请求页面时,该页面将调用查询。 这个查询(我将在稍后发布)在页面加载时效果很好,并且可以成功插入我提供的虚拟数据。
单击一个按钮,我就使用jQuery通过Ajax $ .post调用了相同的查询。 但是,当我执行此$ .post并调用此查询时,每次都会收到内部服务器错误。 一切都完全一样,包括传递的信息; 唯一的区别似乎是是否在页面加载或通过$ .post调用它。
这是错误:
以下是执行页面加载查询的代码:
routes.php
将HTTP get请求发送到名为AppController.php
的文件
routes.php文件 AppController.php
然后使用从DeviceCheckoutController.php
获取的以下数组制作页面
然后转到DeviceCheckout.php
我能够在页面上回显$ 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'部分:
然后返回到先前在DeviceCheckout.php
显示的查询
最后,这是我的数据库结构供参考:
关于为什么会这样的任何解释? 另外,由于我对框架的使用和总体编程经验不足,所以请非常感谢Laravel或其他一般最佳实践技巧。
抱歉,这么长的帖子,我希望有足够的信息来诊断此问题。 让我知道是否需要添加其他内容。
编辑:页面顶部包含的错误图片。
一切都完全一样,包括传递的信息
不,不是。 如果完全一样,您将不会得到错误。
通过猜测可能是什么问题,很难解决这类问题。 你需要
设置您的系统,以便Laravel将日志错误记录到laravel.log文件中
设置您的PHP系统,使Laravel无法处理的错误记录到Web服务器的错误日志(和/或PHP的错误日志)中
将Laravel置于调试模式,以便在屏幕上输出错误,并通过Firebug或Chrome查看ajax请求的输出
一旦遇到实际的PHP错误,通常通常很容易看到您认为相同的请求有何不同,然后解决该问题。
在朋友的一些建议下,我找到了解决问题的办法。 比我预期的要容易得多,比这里或其他地方提供给我的任何解决方案都容易。
本质上,我需要做的是在模型函数中放置try,catch子句,然后如果遇到异常,则将其存储在变量中, return
其return
,然后使用console.log()
查看该异常。 这是一个模仿我的观点的例子:
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;
}
}
然后在View(或模型函数返回到的任何位置)上,只需console.log()
即可将POST的输出。 这将显示成功查询的结果,如果遇到异常而不是无用的Internal Server Error 500消息,则显示异常的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.