Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
为什么有时候从angularjs向API函数发送对象数组时会出现get 404 not found错误?_Angularjs_Laravel - Fatal编程技术网

为什么有时候从angularjs向API函数发送对象数组时会出现get 404 not found错误?

为什么有时候从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

当我向API函数发送javascript对象的字符串化数组时,有时会出现404NotFound错误

我已尝试更改发送数据的方法(POST、UPDATE等)。我已经意识到,如果我减少数组中的对象数量,就不会抛出404错误

在angularjs端,代码是:

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)
            }
        );
  • 端点api url是正确的,请记住,它只是有时起作用,如果数组长度减少,错误就不会出现
  • console.log(计划发送)打印以下内容:
  • 拉威尔控制器:
  • Api路由:
  • 我没有发现任何错误,有时会出现以下错误:

    异常:“Symfony\Component\HttpKernel\exception\NotFoundHttpException” 文件:“D:\MyProject\vendor\laravel\framework\src\illumb\Routing\routedCollection.php”

    重要提示:
    当我减少要发送的数组中的对象数量时,不会发生此错误,另一方面,发送与上面显示的完全相同的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,                 
            },