Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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/9/ruby-on-rails-3/4.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
Php 如何将表单数据导入使用选项方法发布的Laravel5.6控制器_Php_Jquery_Laravel - Fatal编程技术网

Php 如何将表单数据导入使用选项方法发布的Laravel5.6控制器

Php 如何将表单数据导入使用选项方法发布的Laravel5.6控制器,php,jquery,laravel,Php,Jquery,Laravel,我正在为angular的Laravel5.6创建API。 表单数据正在使用OPTIONS方法发送到API。 如何将这些数据输入控制器 我已经这样测试过了 jquery ajax $.ajax({ url:'domain.com/laravel_app/api/register_user', type:"options", dataType:'json', data:{name:'Joe'}, success:function(r) {

我正在为angular的Laravel5.6创建API。 表单数据正在使用OPTIONS方法发送到API。 如何将这些数据输入控制器

我已经这样测试过了

jquery ajax

$.ajax({         
  url:'domain.com/laravel_app/api/register_user',
    type:"options",
    dataType:'json',
    data:{name:'Joe'},
    success:function(r)
    {
        console.log(r);
    }
  }) 
拉维尔路线

Route::match(['post', 'options'], '/register_user/', 'UserController@register_user');
拉威尔控制器

public function register_user(Request $request)
{
    print_r($request->all());

    $arr1['status']='SUCCESS';
    return json_encode($arr1);

}

使用“post”方法一切正常,但不使用“options”

这似乎是jQuery忽略动词并将数据作为请求主体发送的问题

您应该能够通过执行以下操作绕过此问题:

$.ajax({         
  url:'domain.com/laravel_app/api/register_user?'+$.param({name: 'Joe'}),
    type:"options",
    dataType:'json',
    success:function(r)
    {
        console.log(r);
    }
  }) 
但是,请记住,根据:

HTTP OPTIONS方法用于描述目标资源的通信选项


您在此处使用的请求似乎不用于描述目标资源的通信选项,因此您不应为此使用选项方法

只需将其添加到路由文件
Route::options(“{all}”,函数(){$response=response::make(“”);返回$response;})在我的情况下不起作用。如何获取请求的“名称”字段的值?请求的名称字段
Route::options({all}
routes意味着它使用
options
method为任何路由返回空的成功响应。当您调用ajax时,之前会调用该url的options方法以获取CORS信息