前端页面用Extjs向laravel PHP后台发起一个Ajax请求 出现错误代码500 内部服务器错误
Extjs部分代码:
//向PHP中传数据
Ext.Ajax.request({
url: '/demo/interface',
//timeout: 60000,
method: 'POST',
params: {
name: 'abc',
password: '123456',
email: '4578412@qq.com',
},
headers: { "Accept": 'application/json', "Content-Type": 'application/json' },
success:function(response,options){
Ext.Msg.alert('成功!');
},
failure:function(response,options){
Ext.Msg.alert('失败!');
},
});
PHP部分代码:
<?php namespace App\Http\Controllers;
use App\Models\Work as work;
use App\Models\User as user;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
public function getInterface(){
$output = array('users'=>array('name' => 'Abigail', 'password' => 'CA', 'id'=>'1', 'email'=>'456456@qq.com'));
$content = json_encode($output);
return $content;
}
网页上的console信息:POST http://127.0.0.1:81/demo/interface 500 (Internal Server Error)
麻烦各位看看是什么原因,或者说有什么解决办法,十分感谢!!!!!!!
//向PHP中传数据
Ext.Ajax.request({
url: '/demo/interface',
//timeout: 60000,
method: 'POST',
params: {
name: 'abc',
password: '123456',
email: '4578412@qq.com',
},
headers: { "Accept": 'application/json', "Content-Type": 'application/json' },
success:function(response,options){
Ext.Msg.alert('成功!');
},
failure:function(response,options){
Ext.Msg.alert('失败!');
},
});
PHP部分代码:
<?php namespace App\Http\Controllers;
use App\Models\Work as work;
use App\Models\User as user;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
public function getInterface(){
$output = array('users'=>array('name' => 'Abigail', 'password' => 'CA', 'id'=>'1', 'email'=>'456456@qq.com'));
$content = json_encode($output);
return $content;
}
网页上的console信息:POST http://127.0.0.1:81/demo/interface 500 (Internal Server Error)
麻烦各位看看是什么原因,或者说有什么解决办法,十分感谢!!!!!!!
2 个回复
daniel
赞同来自:
<meta name="_token" content="{{ csrf_token() }}"/>
然后在ajax请求header里面加上
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
具体可参考我之前的一个回答(第四个答案):http://wenda.golaravel.com/question/650
xiao774548488
赞同来自: