1. #1
    Sencha User
    Join Date
    Mar 2011
    Posts
    4
    Vote Rating
    0
    eniu is on a distinguished road

      0  

    Default Answered: Authentication (AJAX) - Best practice

    Answered: Authentication (AJAX) - Best practice


    Hi there

    I'm quite new to ExtJs 4. I'm searching for the best practice to handle authentication in ExtJs. I'm able to authenticate with my server but if the session times out and I make an AJAX request (via. json store / AJAX proxy), the server returns the HTTP status 401 (Unauthorized) and no rows were displayed in my grid. How can I catch and handle this HTTP status? If I just display the login form to authenticate there is the problem that there may be multiple AJAX calls with status 401 and the login form is display for each call.

    Any ideas?

    Sorry for my bad english.

    Regards Sven

  2. If I just display the login form to authenticate there is the problem that there may be multiple AJAX calls with status 401 and the login form is display for each call.
    Though it's not clear from what you've said, it sounds like you're proposing trying to authenticate the request. This might be possible but far more common is just to logout the user and show them the login screen. If the login screen is a completely separate page then the problem with multiple Ajax requests is solved. If it isn't a separate page then you may need to manually build logic into your error handling to ensure you don't try to reshow the login form if it's already visible.

    Having a global error handler for Ajax requests as suggested by christocracy is definitely a good idea.

  3. #2
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    380
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default Attach a listener to Ext.Ajax

    Attach a listener to Ext.Ajax


    See the docs for Ext.Ajax: http://docs.sencha.com/ext-js/4-0/#/api/Ext.Ajax

    Attach a listener to #requestcomplete and/or #requestexception.

    Event-handlers attached to Ext.Ajax will fire for every ajax request in the app. It's always a good idea to wire-up some sort of application-wide error-handling of this sort.
    /**
    * @author Chris Scott
    * @business www.transistorsoft.com
    * @rate $120USD / hr; training $500USD / day / developer (5 dev min)
    *
    * @SenchaDevs http://senchadevs.com/developers/transistor-software
    * @twitter http://twitter.com/#!/christocracy
    * @github https://github.com/christocracy
    */

  4. #3
    Sencha User skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,338
    Answers
    498
    Vote Rating
    248
    skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of

      0  

    Default


    If I just display the login form to authenticate there is the problem that there may be multiple AJAX calls with status 401 and the login form is display for each call.
    Though it's not clear from what you've said, it sounds like you're proposing trying to authenticate the request. This might be possible but far more common is just to logout the user and show them the login screen. If the login screen is a completely separate page then the problem with multiple Ajax requests is solved. If it isn't a separate page then you may need to manually build logic into your error handling to ensure you don't try to reshow the login form if it's already visible.

    Having a global error handler for Ajax requests as suggested by christocracy is definitely a good idea.

  5. #4
    Sencha User
    Join Date
    Mar 2011
    Posts
    4
    Vote Rating
    0
    eniu is on a distinguished road

      0  

    Default


    Yes I tried to authenticate the request but I think it would get far to complex. Now I'm just redirecting to the login form. Thank you for your support.

    Best regards
    Sven

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar