Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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/1/php/251.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 5.2时,javascript枚举为空*_Javascript_Php_Ajax_Laravel 5.2 - Fatal编程技术网

发布到Laravel 5.2时,javascript枚举为空*

发布到Laravel 5.2时,javascript枚举为空*,javascript,php,ajax,laravel-5.2,Javascript,Php,Ajax,Laravel 5.2,希望这是一个简单的例子,正如标题中提到的,我正在设置的javascript枚举在服务器上是空的。下面是一段经过删减的代码,您可以进行实验: routes.php Route::post('generalenquiries/send', 'CommsController@send'); layout.blade.php <head> <meta name="csrf-token" content="{{ csrf_token() }}" /> ... &l

希望这是一个简单的例子,正如标题中提到的,我正在设置的javascript枚举在服务器上是空的。下面是一段经过删减的代码,您可以进行实验:

routes.php

Route::post('generalenquiries/send', 'CommsController@send');
layout.blade.php

<head>
    <meta name="csrf-token" content="{{ csrf_token() }}" />
    ...
</head>
CommsController.php

class CommsController extends Controller {
    public function send(Request $request) {
        try {
            // $request->input('message_type') returns empty but $request->input('first_name') displays the correct value.
            echo ($request->input('message_type') ." ". $request->input('first_name'));
            die();
        }
        catch(Exception $e) {
            $response = array (
                'success' => false,
                'message' => $e->getMessage(),
                $request
            );
        }
    }
}

我认为这不是问题所在,但至少应该是
echo($request->input('message_type')@fire是的,你是对的,在调试时,我在调用$request->input时忘记了包含撇号。正如您所说的,这不是问题所在。您一定没有正确发送数据,因为您没有粘贴其余的javascript。使用浏览器中的开发者工具栏查看AJAX请求,确保它发送的POST请求正文中包含
message\u type=GENERAL\u ENQUIRY
。@fire我确实正确发送了数据,因为$request->input('first\u name')显示了我在表单上输入的名称,但出于某种原因,$request->input('message\u type')). 我将查看开发人员工具,以了解您建议的问题,如果仍然找不到问题,我将跳过剩下的javascript。@fire我添加了更多内容,以便更好地了解ajax调用,因此,如果您在我使用开发工具时发现任何问题之前发现了我缺少的东西,请告诉我。我认为这不是问题所在,但至少应该是
echo($request->input('message_type')@fire是的,你是对的,在调试时,我在调用$request->input时忘记了包含撇号。正如您所说的,这不是问题所在。您一定没有正确发送数据,因为您没有粘贴其余的javascript。使用浏览器中的开发者工具栏查看AJAX请求,确保它发送的POST请求正文中包含
message\u type=GENERAL\u ENQUIRY
。@fire我确实正确发送了数据,因为$request->input('first\u name')显示了我在表单上输入的名称,但出于某种原因,$request->input('message\u type')). 我将查看开发人员工具,以了解您建议的问题,如果仍然找不到问题,我将跳过剩下的javascript。@fire我添加了更多内容,以便更好地了解ajax调用,因此,如果您在我使用开发人员工具时发现任何问题之前发现了我缺少的东西,请让我知道。
class CommsController extends Controller {
    public function send(Request $request) {
        try {
            // $request->input('message_type') returns empty but $request->input('first_name') displays the correct value.
            echo ($request->input('message_type') ." ". $request->input('first_name'));
            die();
        }
        catch(Exception $e) {
            $response = array (
                'success' => false,
                'message' => $e->getMessage(),
                $request
            );
        }
    }
}