Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel AngularJS 2.0 http.post返回500(内部服务器错误)_Laravel_Angular - Fatal编程技术网

Laravel AngularJS 2.0 http.post返回500(内部服务器错误)

Laravel AngularJS 2.0 http.post返回500(内部服务器错误),laravel,angular,Laravel,Angular,我试图使用angular 2.0通过我的PHP Laravel API添加一个新的英雄,我总是得到500个内部服务器错误响应 我的API(laravel):创建新的英雄路线: Route::group(array('prefix' => 'api/v1', 'middleware' => ['web']), function() { //Add a new hero Route::post('/heroes/create', 'HeroControll

我试图使用angular 2.0通过我的PHP Laravel API添加一个新的英雄,我总是得到500个内部服务器错误响应

我的API(laravel):创建新的英雄路线:

Route::group(array('prefix' => 'api/v1', 'middleware' => ['web']), function()
    {   
     //Add a new hero
    Route::post('/heroes/create', 'HeroController@store');
    });
HeroController@store方法:(使用Laravel表格进行测试和工作)

Angular onSubmit()方法:(尝试使其在没有表单的情况下工作..)

我得到的是:

POST http://127.0.0.1/heroWorld/public/api/v1/heroes/create 500 (Internal Server Error)

怎么了?我尝试了几天来修复它,但没有任何效果。

您使用
URLSearchParams
类创建表单数据,但在
post
方法中使用了另一个对象。您可以尝试以下方法:

let formPayload = new URLSearchParams();
formPayload.set('name', name.value);
formPayload.set('description', desc.value);
formPayload.set('_token', _token.value);

this.http.post('http://127.0.0.1/heroWorld/public/api/v1/heroes/create', 
                   formPayload.toString(), // <------
                   {headers:headers})
let formPayload=new URLSearchParams();
formPayload.set('name',name.value);
formPayload.set('说明',说明值);
formPayload.set(“\u-token”,“\u-token.value”);
this.http.post('http://127.0.0.1/heroWorld/public/api/v1/heroes/create', 

formPayload.toString(),//我做它只是为了测试,在这两种情况下我都得到500(内部服务器错误)你在服务器端有相应的错误吗?我有一个laravel“Add Hero form”,它将数据发送到我的store()方法,并且工作正常(正如我在帖子中提到的)。似乎我在anulgar应用程序中遗漏了一些东西。。
POST http://127.0.0.1/heroWorld/public/api/v1/heroes/create 500 (Internal Server Error)
let formPayload = new URLSearchParams();
formPayload.set('name', name.value);
formPayload.set('description', desc.value);
formPayload.set('_token', _token.value);

this.http.post('http://127.0.0.1/heroWorld/public/api/v1/heroes/create', 
                   formPayload.toString(), // <------
                   {headers:headers})