Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
表格AJAX提交symfony不';行不通_Ajax_Forms_Symfony - Fatal编程技术网

表格AJAX提交symfony不';行不通

表格AJAX提交symfony不';行不通,ajax,forms,symfony,Ajax,Forms,Symfony,我不明白为什么我的AJAX提交不起作用 我在控制器中有两种形式: $intervento = new Intervento(); $form = $this->createForm(InterventoType::class, $intervento); $form->handleRequest($request); $user = new User(); $form_user = $this->createForm(UserType::class, $user); $fo

我不明白为什么我的AJAX提交不起作用

我在控制器中有两种形式:

$intervento = new Intervento();
$form = $this->createForm(InterventoType::class, $intervento);

$form->handleRequest($request);

$user = new User();
$form_user = $this->createForm(UserType::class, $user);
$form_user->handleRequest($request);

if ($form_user->isSubmitted() && $form_user->isvalid()) {
    $response = new Response();
    return $this->json(array('risultato' => ' ok'));
}

if ($form->isSubmitted() && $form->isvalid()) { }

return $this->render('interventi/collaudo.html.twig', array(
    'form' => $form->createView(),
    'form_utente' => $form_user->createView(),
));
在我的小树枝文件中,我启动表单并使其工作:

{{form_start(form_utente,{'attr':{'id':'form-utente'}})}}
    .....
            <div class="row">
                <div class="input-field col s4">
                    <input type="submit" class="waves-effect waves-light btn-large" value="Submit">
                </div>
            </div>
        </div>
    </div>
{{form_end(form_utente)}}
</div>
我在这个JavaScript中还有另一个AJAX调用,但我不认为这会带来问题

“提交”按钮有时返回
错误500
,有时返回
未定义的
警报

我想它不会在控制器中提交,但我不知道为什么


有人能帮我吗?

使用for js URL。您需要公开您的路由。

能否从浏览器控制台或symfony工具栏显示有关请求/响应的信息?控制台为空或加载资源失败:服务器响应状态为500(内部服务器错误)。是否使用dev env?->prod environment->dev environment为什么不使用for js URL。您需要公开您的路由。
$('#form-utente').submit(function(e) {
    e.preventDefault();
    var form = $(this);
    $.ajax({
        type: form.attr('method'),
        url: form.attr('action'),
        data: form.serialize(),
        success: function (data) {
            alert(data['risultato']);
            // setTimeout(function() { window.location.href = "#" }, 500);
            // setTimeout(function() { $("#form-stufa").click() }, 500);
        },
        error: function(){
        }
    });
});