FOSUserBundle(登录/注册)+ AJAX + Symfony2的 [英] FOSUserBundle (login / register) + AJAX + Symfony2

查看:170
本文介绍了FOSUserBundle(登录/注册)+ AJAX + Symfony2的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我装 FOSUserBundle 我的的Symfony2 的网站,我overwrited登录和注册页面。它的工作非常好,但现在,我有另外一个问题:

I installed FOSUserBundle on my Symfony2 website and I overwrited the login and register pages. It's working very well, but now, I have another issue :

将弹出与 AJAX 检查登录和注册部分,具有不同的路线,控制器,工作等。

Making a pop up with an AJAX check for the login and register part, working with the different routes, controllers, etc.

如何做到这一点的最好方法是什么?

How to do that the best way ?

我的弹出是 login.html.twig 页的一个简单的引导模式 FOSUserBundle ,这里是$ C $的c中的模体为登录的一部分(我将使用登记表的寄存器部分):

My pop up is a simple bootstrap modal of login.html.twig page for FOSUserBundle, here is the code of the modal-body for the login part (I will use the register form for the register part) :

<div class="modal-body">
    {% trans_default_domain 'FOSUserBundle' %}

    {% block fos_user_content %}
        <form action="{{ path("fos_user_security_check") }}" method="post">
            <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

            <label for="username">{{ 'security.login.username'|trans }}</label>
            <input type="text" id="username" name="_username" value="" required="required" />

            <label for="password">{{ 'security.login.password'|trans }}</label>
            <input type="password" id="password" name="_password" required="required" />
            <br /><br />
            <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
        </form>
    {% endblock fos_user_content %}
</div>

我已经搜查计算器及其他网站,但没有找到很好的答案我一直在寻找。

I already searched on StackOverflow and other websites but didn't find the good answer I was looking for.

感谢你。

推荐答案

没有当您使用AJAX标记

no token when you use AJAX

user=$('#username').val();
pass=$('password').val();
$.ajax(
     {
     type: "POST",
     url: "{{ path ('your-rout')}}",
     data: {'user': user,'pass':pass},
      beforeSend: function() {
       },
      success: function(json) {}
});

这篇关于FOSUserBundle(登录/注册)+ AJAX + Symfony2的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆