Always send certain values with an ajax request/post

Posted by DZittersteyn on Stack Overflow See other posts from Stack Overflow or by DZittersteyn
Published on 2012-09-06T08:58:40Z Indexed on 2012/09/27 15:37 UTC
Read the original article Hit count: 179

Filed under:
|

I'm building a system that displays a list of user, and on selection of a user requests some form of password. These values are saved in a hidden field on the page, and need to be sent with every request as a form of authentication. (I'm aware of the MITM-vulnerability that lies herein, but it's a very low-key system, so security is not a large concern).

Now I need to send these values with each and every request, to auth the currently 'logged in' user. I'd like to automate this, via ajaxSetup, however i'm running into some issues.

My first try was:

init_user_auth: function(){
    $.ajaxSetup({
        data: {
            'user'    : site_user.selected_user_id(),
            'passcode': site_user.selected_user_pc(),
            'barcode' : site_user.selected_user_bc()
        }
    });
},

However, as I should have known, this reads the values once, at the time of the call to ajaxSetup, and never rereads them. What I need is a way to actually call the functions every time an ajax-call is made.

I'm currently trying to understand what is happening here: https://groups.google.com/forum/?fromgroups=#!topic/jquery-dev/OBcEfgvTJ9I, however through the flamewar and very low-level stuff going on there, I'm not exactly sure I get what is going on.

Is this the way to proceed, or should I just face facts and manually add login-info to each ajax-call?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX