![](/img/trans.png)
[英]How to fix 500 (Internal Server Error) Vue js - Laravel (Edited)
[英]Internal server error 500 when postig data to laravel project using Axios in Vue.js
我試圖在Vue中使用axios將數據發送到我的laravel應用程序,但出現此錯誤
Error: Request failed with status code 500
at e.exports (axios.min.js:8)
at e.exports (axios.min.js:8)
at XMLHttpRequest.l.(anonymous function) (http://localhost:8000/js/axios.min.js:8:3282)
Axios代碼:
addExperience: function () {
axios.post(window.Laravel.url + '/addexperience', this.experience)
.then(response => {
console.log(response.data)
if(response.data.etat){
this.open = false;
this.experiences.push(this.experience);
}})
.catch(error => {
console.log(error);
console.log(window.Laravel.url + '/addexperience');
console.log(this.experience.titre);
console.log(this.experience);
});
}
},
路線:
Route::post('/addexperience', 'CvController@addExperience');
控制器:
public function addExperience(Request $request){
$exp = new Experience();
$exp->titre = $request->titre;
$exp->description = $request->description;
$exp->debut = $request->debut;
$exp->fin = $request->fin;
$exp->cv_id = $request->cv_id;
$exp->save();
return Response()->json(['etat' => true, 'id' =>$exp->id]);
}
請幫我
錯誤500
通常表示后端出現了問題,因此您可以檢查瀏覽器的控制台>網絡並檢查laravel拋出的錯誤,而沒有我們只能猜測的信息。 所以讓我們猜測
由於我們不知道您使用的是哪個laravel版本,我會假設您使用的是5.x
public function addExperience(Request $request){
$exp = new Experience(); //Maybe this model wasnt injected, do use App\Experience; to do so
//(Generally models are added in the app directory, if yours is in a subforlder just add it to the path, use App\folder\Experience);
$exp->titre = $request->titre;
$exp->description = $request->description;
$exp->debut = $request->debut;
$exp->fin = $request->fin;
$exp->cv_id = $request->cv_id;
$exp->save();
return Response()->json(['etat' => true, 'id' =>$exp->id]);
//if youre using the response helper it should be in lowercase "response()" if you're using the facade you must import the dependency with use Illuminate\Support\Facades\Response;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.