为什么有时候从angularjs向API函数发送对象数组时会出现get 404 not found错误?
当我向API函数发送javascript对象的字符串化数组时,有时会出现404NotFound错误 我已尝试更改发送数据的方法(POST、UPDATE等)。我已经意识到,如果我减少数组中的对象数量,就不会抛出404错误 在angularjs端,代码是:为什么有时候从angularjs向API函数发送对象数组时会出现get 404 not found错误?,angularjs,laravel,Angularjs,Laravel,当我向API函数发送javascript对象的字符串化数组时,有时会出现404NotFound错误 我已尝试更改发送数据的方法(POST、UPDATE等)。我已经意识到,如果我减少数组中的对象数量,就不会抛出404错误 在angularjs端,代码是: var schedule_to_send = JSON.stringify(my_array_of_objects); console.log(schedule_to_send); $http({ method: 'POS
var schedule_to_send = JSON.stringify(my_array_of_objects);
console.log(schedule_to_send);
$http({
method: 'POST',
url: API_URL + 'schedule/update_or_add/',
params: {
schedule_days: schedule_to_send,
},
}).then(function successCallback(response) {
console.log(response);
},
function errorCallback(response) {
console.log(response)
}
);
当我减少要发送的数组中的对象数量时,不会发生此错误,另一方面,发送与上面显示的完全相同的json(schedule_to_send)有时会发生错误,有时不会,而且效果很好。正如georgeawg建议的那样,只需在body Post中发送json即可。我已将上述代码更改为正确的工作方式 更改自:
params: {
schedule_days: schedule_to_send,
},
致:
代码发送URL中的数据,而不是POST请求的主体。在POST请求的正文中发送数据会更明智。你完全正确。谢谢。
public function updateoradd(Request $request)
{}
Route::prefix('schedule')->group(function () {
Route::post('update_or_add', 'ScheduleController@updateoradd');
params: {
schedule_days: schedule_to_send,
},
data: {
schedule_days: schedule_to_send,
},