dqxafj6830 2016-11-29 13:26
浏览 86
已采纳

使用表单数据添加laravel CSRF令牌

While uploading an image via wysiwyg editor I need to pass the Laravel CSRF token with the FormData(). But it seems like it fails or it does not add the csrf token using the append() method.

Here is my code:

  function uploadImage( image ) {
    var data = new FormData();
    data.append( "image", image );

    data.append( "csrfToken", Laravel.csrfToken ); // <- adding csrf token
    // Laravel.csrfToken will return the csrf token.

    console.log( data.entries() );
    $.ajax ({
      data: data,
      type: "POST",
      url: "/article/store/image",
      cache: false,
      contentType: false,
      processData: false,
      success: function(url) {
        var image = IMAGE_PATH + url;
          $( '#editor' ).summernote( "insertImage", image );
        },
        error: function( data ) {
          console.log( data );
        }
    });
  }

enter image description here

Its not adding the laravel csrf token with the form data because still I am getting an error

TokenMismatchException in VerifyCsrfToken.php line 68

How to add the token with the form data?

  • 写回答

3条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Multisim14.0软件安装
      • ¥15 一块GD32F105芯片的主板。怎么找RXD和TXD串口
      • ¥15 磁盘异常导致工业相机GigE传图卡顿
      • ¥20 python中使用chatgpt为什么一直连接失败
      • ¥50 使用grpc遇到的问题
      • ¥100 运算速度优化问题,控制在四秒以内
      • ¥15 如何用matlab画出这样的图
      • ¥15 线性回归问题进行特征缩放后,为什么求得的参数不对了
      • ¥15 python爬取网页信息(主要为期刊影响因子、官网等),已有ISSN进行检索,但爬取过程找不到class该怎么办?
      • ¥15 找出5阶幻方的所有解的个数:275305224