php ajax parsererror,laravel中ajax请求一直报parsererror错误

laravel5.4中使用ajax请求控制器接口一直报错

admin.js

$.ajaxSetup({

headers: {

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

}

});

$(".post-audit").click(function(){

var status = $(this).attr("post-action-status");

var post_id = $(this).attr("post-id");

var _self = $(this);

$.ajax({

url: "/admin/post/"+post_id+"/operate",

method: "POST",

data: {"status": status},

dataType:"json",

success: function handleSuccess(data){

console.log(data);

//操作后该项不显示

//_self.parent().parent().remove();

},

error: function(xhr, type){

console.log(type);

}

});

});

控制器

public function operate(Post $post)

{

return ['code'=>200,'msg'=>'测试'];

/*$this->validate(request(), [

"status" => 'required|in:-1,1',

]);

$post->status = request('status');

$post->save();

return response()->json([

'error' => 0,

'msg' => ''

]);*/

}

上面的请求浏览器控制台一直提示parsererror:

bV4yH3?w=1917&h=254

但是将返回数据写在路由里又是正常的

Route::post('/admin/post/{post}/operate',function(){

return ['code'=>200,'msg'=>'测试'];

})->where('post','[0-9]+');

浏览器控制台输出:

bV4yKQ?w=1913&h=329

小弟新手,请大神多多指教

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值