【问题标题】:post 500 (internal server error) ajax though using csrf token in laravel发布 500(内部服务器错误)ajax 尽管在 laravel 中使用 csrf 令牌
【发布时间】:2018-06-19 12:33:15
【问题描述】:

虽然我在我的 html 文件中使用{{ csrf_field() }} 仍然得到POST http://localhost:8000/add_user 500 (Internal Server Error)

这是我的代码

$.ajax({

    url:"/add_user",                       
    type: 'post',
    data: {_token : token, user_type_id : user_type_id,  full_name : full_name,  email : email, password : password,  username : username, date : date},
                        success:function(msg){

    $("#report").load(location.href + " #report");

   }
});

【问题讨论】:

  • 你从哪里得到你的令牌?使用 ajax(而不是 AXIOS)时,您需要在 javascript 中包含类似 var csrf_token = $('meta[name="csrf-token"]').attr('content'); 的内容
  • @kerbholz...我已将{{ csrf_field() }} 添加到我的表单中
  • 你的表单在使用 ajax 时没有被提交
  • @ kerbholz....我已经使用相同类型的 ajax 函数完成了删除和更新部分。但是在添加部分显示了这个错误......它没有提交我得到了那个兄弟。但是我想知道的错误在哪里:(

标签: php jquery ajax laravel-5.3


【解决方案1】:

你可以用 csrf 令牌做到这一点

$.ajax({
  type: "POST",
  url: "url/update",
  dataType: 'json',
  data: 'id=' + id+ '&_token={{csrf_token()}}',

【讨论】:

    【解决方案2】:

    提供您的服务器路由器,它s seems 就像您在您的服务器上错过了这个路由请求

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-05
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 2014-09-22
      • 2017-04-10
      • 2018-07-21
      • 2019-05-24
      相关资源
      最近更新 更多