laravel POST 请求中的 500

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38500637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:11:38  来源:igfitidea点击:

500 in POST request

javascriptphpjqueryajaxlaravel

提问by YaSh Chaudhary

I am building edit post system using jquery and ajax in laravel 5.2. When i click on save changes button in my bootstrap modal, the following error is displayed:

我正在 Laravel 5.2 中使用 jquery 和 ajax 构建编辑发布系统。当我在引导模式中单击保存更改按钮时,显示以下错误:

Error: POST http://localhost:8000/edit 500 (Internal Server Error)

send @ jquery-1.12.0.min.js:4

ajax @ jquery-1.12.0.min.js:4

(anonymous function) @ myplace.js:24

dispatch @ jquery-1.12.0.min.js:3

r.handle @ jquery-1.12.0.min.js:3
Error: POST http://localhost:8000/edit 500 (Internal Server Error)

send @ jquery-1.12.0.min.js:4

ajax @ jquery-1.12.0.min.js:4

(anonymous function) @ myplace.js:24

dispatch @ jquery-1.12.0.min.js:3

r.handle @ jquery-1.12.0.min.js:3

js code:

js代码

$('#modal-save').on('click' , function() {

$.ajax({

    method : 'POST' ,
    url : url ,
    data: { body: $('#post-body').val(), postid: '' , _token: token }})

.done(function(msg) {

    console.log(msg['message']);

});});

included in my view file:

包含在我的视图文件中

<script>
var token='{{ Session::token() }}';
var url='{{  route('edit') }}' ;
</script>

回答by chf

First, as suggested, you have to check your log for a detailed cause. Futhermore, I suppose that you need to stringify your data:

首先,按照建议,您必须检查日志以了解详细原因。此外,我想您需要对数据进行字符串化:

$.ajax({

 method : 'POST' ,
 url : url ,
 data: JSON.stringify({ body: $('#post-body').val(), postid: '' , _token: token  })
}).done(function(msg) {

 console.log(msg['message']);

});