Symfony2 AJAX Login

前端 未结 7 2729
谎友^
谎友^ 2020-11-28 01:42

I have an example where I am trying to create an AJAX login using Symfony2 and FOSUserBundle. I am setting my own success_handler and failure_handler

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 02:41

    I handled this entirely with javascript:

    if($('a.login').length > 0) { // if login button shows up (only if logged out)
            var formDialog = new MyAppLib.AjaxFormDialog({ // create a new ajax dialog, which loads the loginpage
                title: 'Login',
                url: $('a.login').attr('href'),
                formId: '#login-form',
                successCallback: function(nullvalue, dialog) { // when the ajax request is finished, look for a login error. if no error shows up -> reload the current page
                    if(dialog.find('.error').length == 0) {
                        $('.ui-dialog-content').slideUp();
                        window.location.reload();
                    }
                }
            });
    
            $('a.login').click(function(){
                formDialog.show();
                return false;
            });
        }
    

    Here is the AjaxFormDialog class. Unfortunately I have not ported it to a jQuery plugin by now... https://gist.github.com/1601803

提交回复
热议问题