Laravel 5.2 仅从 AJAX POST 请求中检索数值


laravel 5.2 only retrieves numeric value from ajax post request

我正在使用ajax提交我的表单,我注意到只传递了数值,因为当我在提交表单之前检查变量时,变量都被填充了。 但是当它们到达我的控制器时,只有数字的会变得低谷。

阿贾克斯:

function approveForm(id){
            var mystring, stringie, approvier, tokens;
            $.ajax({
                type: "POST",
                url: baseUrl + '/approveForm',
                data: {id:id, "_token": token},
                dataType: "json",
                success: function(data){
                    stringie = data.toString();
                    mystring = stringie.replace(/[,]/g, '');
                    $("#myModal3 .modal-content").html(mystring);
                    approvier = $('#approvier').val();
                    tokens = $("input[name=_token]").val();
                    $('#myFmeaForm').on('submit', function(e){
                        alert(id);
                        e.preventDefault();
                        $.ajax({
                            type: "POST",
                            url: baseUrl + '/verifyForm',
                            data: {id:id, approvier: approvier, "_token": tokens},
                            dataType: "json",
                            success: function(data){
                                alert(data);
                                if(data){
                                    window.location.reload();
                                }
                            }
                        });
                    });
                }   
            }); 
        }

我的控制器:

public function verifyForm(){
        return Input::get('approvier');
    }

我尝试对批准者变量使用数字和字母数字,当它的数字时它会下降,但当它的 aplhanumeric 时它不会

一般来说,最好的方法是无论如何序列化表单.....

这是jquery参考,但标准JS也有它:

https://api.jquery.com/serialize/

所以你的:data: {id:id, "_token": token},

成为:data: $('#formID').serialize(),