<legend id='gJ6iI'><style id='gJ6iI'><dir id='gJ6iI'><q id='gJ6iI'></q></dir></style></legend>

  • <i id='gJ6iI'><tr id='gJ6iI'><dt id='gJ6iI'><q id='gJ6iI'><span id='gJ6iI'><b id='gJ6iI'><form id='gJ6iI'><ins id='gJ6iI'></ins><ul id='gJ6iI'></ul><sub id='gJ6iI'></sub></form><legend id='gJ6iI'></legend><bdo id='gJ6iI'><pre id='gJ6iI'><center id='gJ6iI'></center></pre></bdo></b><th id='gJ6iI'></th></span></q></dt></tr></i><div id='gJ6iI'><tfoot id='gJ6iI'></tfoot><dl id='gJ6iI'><fieldset id='gJ6iI'></fieldset></dl></div>
    • <bdo id='gJ6iI'></bdo><ul id='gJ6iI'></ul>

    1. <small id='gJ6iI'></small><noframes id='gJ6iI'>

      <tfoot id='gJ6iI'></tfoot>

        ajax请求中的laravel TokenMismatchException

        laravel TokenMismatchException in ajax request(ajax请求中的laravel TokenMismatchException)
        • <bdo id='w0PjU'></bdo><ul id='w0PjU'></ul>
          <i id='w0PjU'><tr id='w0PjU'><dt id='w0PjU'><q id='w0PjU'><span id='w0PjU'><b id='w0PjU'><form id='w0PjU'><ins id='w0PjU'></ins><ul id='w0PjU'></ul><sub id='w0PjU'></sub></form><legend id='w0PjU'></legend><bdo id='w0PjU'><pre id='w0PjU'><center id='w0PjU'></center></pre></bdo></b><th id='w0PjU'></th></span></q></dt></tr></i><div id='w0PjU'><tfoot id='w0PjU'></tfoot><dl id='w0PjU'><fieldset id='w0PjU'></fieldset></dl></div>

            <tbody id='w0PjU'></tbody>

          • <small id='w0PjU'></small><noframes id='w0PjU'>

              <tfoot id='w0PjU'></tfoot>

                  <legend id='w0PjU'><style id='w0PjU'><dir id='w0PjU'><q id='w0PjU'></q></dir></style></legend>
                1. 本文介绍了ajax请求中的laravel TokenMismatchException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用资源组并使用此过滤器来解决 TokenMismatchException 问题:

                  i'm using resource group and use this filter to resolve TokenMismatchException problem:

                  Route::filter('csrf', function($route, $request) {
                      if (strtoupper($request -> getMethod()) === 'GET') {
                          return;
                          // get requests are not CSRF protected
                      }
                  
                      $token = $request -> ajax() ? $request -> header('X-CSRF-Token') : Input::get('_token');
                  
                      if (Session::token() != $token) {
                          throw new IlluminateSessionTokenMismatchException;
                      }
                  });
                  

                  我的路线:

                  Route::group(array('prefix'=> 'admin', 'before' => 'csrf'), function(){
                      Route::resource('profile' , 'ProfileController', array('as'=>'profile') );
                  });
                  

                  现在.我收到 Ajax 请求错误,例如此代码:

                  now. i get error to Ajax requests such as this code:

                  <script type="text/javascript">
                      $(document).ready(function() {
                         $('#frm').submit(function(e){
                             e.preventDefault();
                             name         = $('#name').val();
                             family       = $('#family').val();
                             email        = $('#email').val();
                             currPassword = $('#currPassword').val();
                             password     = $('#password').val();
                             password_confirmation = $('#password_confirmation').val();     
                  
                             $.post("{{ route('admin.profile.update', $profile->id) }}",
                                  { 
                                    _method : 'PUT',
                                    name                  : name,
                                    family                : family,
                                    email                 : email,
                                    currPassword          : currPassword,
                                    password              : password,
                                    password_confirmation : password_confirmation  
                                  },
                                  function(data)
                                  {
                                      alert(data.errors.name);
                                  },'json');
                                  return false;
                         });
                  });
                  </script>
                  

                  错误:

                  {"error":{"type":"Illuminate\Session\TokenMismatchException","message":"","file":"/var/www/alachiq/app/filters.php","line":83}}
                  

                  我认为我必须在 $.post 中发送 _token.但我无法获得具有 name 属性的 input 标记.我得到这个错误:

                  i think i'm must be sent _token in $.post. but i can not get input tag with name attribute. iget this error:

                  TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement.
                  

                  推荐答案

                  Laravel 文档中有一个关于如何做到这一点的提示.这在提出问题时可能不可用,但我想我会用答案更新它.

                  There is a tip in the Laravel docs on how to do this. This might not have been available at the time of the question, but I thought I would update it with a answer.

                  http://laravel.com/docs/master/routing#csrf-x-csrf-令牌

                  我已经测试了文档中的元标记方法并使其正常工作.将以下元标记添加到您的全局模板中

                  I have tested the meta tag method from the documentation and got it working. Add the following meta tag into your global template

                  <meta name="csrf-token" content="{{ csrf_token() }}">
                  

                  添加此 JavaScript,为 jQuery 中的所有 ajax 请求设置默认值.最好在您的应用中包含的 js 文件中.

                  Add this JavaScript that sets defaults for all ajax request in jQuery. Preferably in a js file that is included across your app.

                  $.ajaxSetup({
                      headers: {
                          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                      }
                  })
                  

                  此令牌可以存在于请求标头或表单中.这会将其填充到每个 ajax 请求的请求标头中.

                  This token can exist in the request header or the form. This populates it into the request header of every ajax request.

                  这篇关于ajax请求中的laravel TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    • <tfoot id='x2Bf2'></tfoot>

                      <small id='x2Bf2'></small><noframes id='x2Bf2'>

                        <bdo id='x2Bf2'></bdo><ul id='x2Bf2'></ul>

                          <i id='x2Bf2'><tr id='x2Bf2'><dt id='x2Bf2'><q id='x2Bf2'><span id='x2Bf2'><b id='x2Bf2'><form id='x2Bf2'><ins id='x2Bf2'></ins><ul id='x2Bf2'></ul><sub id='x2Bf2'></sub></form><legend id='x2Bf2'></legend><bdo id='x2Bf2'><pre id='x2Bf2'><center id='x2Bf2'></center></pre></bdo></b><th id='x2Bf2'></th></span></q></dt></tr></i><div id='x2Bf2'><tfoot id='x2Bf2'></tfoot><dl id='x2Bf2'><fieldset id='x2Bf2'></fieldset></dl></div>
                              <tbody id='x2Bf2'></tbody>
                            <legend id='x2Bf2'><style id='x2Bf2'><dir id='x2Bf2'><q id='x2Bf2'></q></dir></style></legend>