Laravel Ajax返回500(内部服务器错误) [英] Laravel ajax returns 500 (Internal Server Error)
问题描述
Laravel ajax返回500(内部服务器错误).你能告诉我是什么问题吗?
Laravel ajax returns 500 (Internal Server Error). Could you tell me what is the problem?
sample.brade.php
<script type="text/javascript">
$("input.dog_check").click(function(){
var amount = 10000;
var dataString = 'amount='+amount;
console.log(dataString);
$.ajax({
type:'POST',
data:dataString,
url: 'save_temporary_data',
success:function(data) {
alert(data);
}
});
});
</script>
routes.php
Route::post('/save_temporary_data', 'PaymentsController@saveTemporaryData');
PaymentsController.php
~~~
public function saveTemporaryData(){
if (Request::ajax()){
$amount = $_POST['amount'];
$insert = "insert into temporary_data values('$amount')";// Do Your Insert Query
if(mysql_query($insert)) {
echo "Success";
} else {
echo "Cannot Insert";
}
}
}
~~~
更新
我在 sample.blade.php
中添加了<元名称="csrf-token" content ="{{csrf_token()}}">
和以下内容.但是,它不能解决问题.
update
I added <meta name="csrf-token" content="{{ csrf_token() }}">
and the following into sample.blade.php
. However it cannot solve the problem.
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
sample.blade.php
<head>
<link rel="stylesheet" href="/css/header.css">
<link rel="stylesheet" href="/css/common.css">
<link rel="stylesheet" href="/css/reset.css">
<link rel="stylesheet" href="/css/edit_profile.css">
<link rel="stylesheet" href="/css/footer.css">
<link rel="stylesheet" href="/css/host_profile.css">
<link rel="stylesheet" href="/css/validationEngine.jquery.css">
<meta name="csrf-token" content="{{ csrf_token() }}">
</head>
~~~
$("input.dog_check").click(function(){
var amount = 10000;
var dataString = 'amount='+amount;
console.log(dataString);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type:'POST',
data:dataString,
url: 'save_temporary_data',
success:function(data) {
alert(data);
}
});
});
推荐答案
没有错误,没人可以做任何事情您可以手动检查日志.在/storage/logs中.但是,如果您想看到现场"错误,请执行以下操作.提交之前,请打开开发者控制台并转到网络"选项卡.提交ajax请求.然后,您会在网络"标签中看到红色的请求.单击它,在右侧有预览选项卡.在预览"选项卡中将显示laravel格式的消息.希望这对您的调试有所帮助
Without the error nobody can't do anything You can Check your logs manually. in /storage/logs. But if you want to see the error "on site" Do the following. Before you submit open the developer console and go to the networking tab. submit the ajax request. And you will get the red request in the networking tab. Click on it, and on the right side there is the preview tab. In the preview tab will be the laravel formatted message. Hope this helps with your debugging
这篇关于Laravel Ajax返回500(内部服务器错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!