php ajax提交报异常,在ajax请求中的php – laravel TokenMismatchException异常

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

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 Illuminate\Session\TokenMismatchException;

}

});

我的路线:

Route::group(array('prefix'=> 'admin', 'before' => 'csrf'), function(){

Route::resource('profile' , 'ProfileController', array('as'=>'profile') );

});

现在。我收到Ajax请求的错误,如这段代码:

$(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;

});

});

错误:

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

我想我必须在_ .post中发送_token。但是我不能使用name属性获取输入标签。 iget这个错误:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值