vue提交时出现错误: ‘_token‘: LA.token, Uncaught (in promise) ReferenceError: LA is not defined

在Vue应用中,提交表单时遇到LA.token引用错误。问题在于LA对象未定义,导致_token:LA.token报错。通过将_token的值更改为使用csrf_token()函数获取,成功避免了错误并完成了POST请求。csrf_token()函数在helpers.php文件中定义,确保了CSRF保护。
摘要由CSDN通过智能技术生成

vue提交时出现错误: ‘_token’: LA.token, Uncaught (in promise) ReferenceError: LA is not defined

submitBtn() {
   var that = this

   that.$confirm('确认提交? 提交之后不能修改 !', '提示', {
     confirmButtonText: '确定',
     cancelButtonText: '取消',
     type: 'warning'
   }).then(() => {
     that.loading = true;
     jQuery.ajax({
       url: "/hismaterial/saveRedo",
       type: "post",
       data: {
         // '_token': LA.token,  //这样会报错
         '_token':'{{ csrf_token() }}', //改成这样子就不会了
         'notice_id': that.notice_id,
         'redoList': that.redoList,
         'liable': that.liable,
       },
       dataType: 'json',
       success: function (res) {
         that.loading = false;
         that.causeDrawer = false;
         if (res.code == 1) {
           that.$message({
             message: res.msg,
             type: 'success'
           })
           that.getData();
         } else {
           that.$message({
             message: res.msg,
             type: 'warning'
           })
         }

       }
     });
   })


 }

文件:helpers.php

if (! function_exists('csrf_token')) {
    /**
     * Get the CSRF token value.
     *
     * @return string
     *
     * @throws \RuntimeException
     */
    function csrf_token()
    {
        $session = app('session');

        if (isset($session)) {
            return $session->token();
        }

        throw new RuntimeException('Application session store not set.');
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值