| | 12 | === AJAX === |
| | 13 | |
| | 14 | Authenticate using: |
| | 15 | {{{ |
| | 16 | function make_base_auth(user, password) { |
| | 17 | var tok = user + ':' + pass; |
| | 18 | var hash = Base64.encode(tok); |
| | 19 | return 'Basic ' + hash; |
| | 20 | } |
| | 21 | |
| | 22 | var auth = make_basic_auth('username', 'password'); |
| | 23 | var url = 'http://host.domain/eden/controller/function?vars'; |
| | 24 | |
| | 25 | // RAW |
| | 26 | request = new XMLHttpRequest(); |
| | 27 | request.setRequestHeader('Authorization', auth); |
| | 28 | request.open('PUT', url, true); // async=true |
| | 29 | request.send(bodyContent); |
| | 30 | |
| | 31 | // ExtJS |
| | 32 | Ext.Ajax.request({ |
| | 33 | url : url, |
| | 34 | method : 'GET', |
| | 35 | headers : { Authorization : auth } |
| | 36 | }); |
| | 37 | |
| | 38 | // jQuery |
| | 39 | $.ajax({ |
| | 40 | url : url, |
| | 41 | method : 'GET', |
| | 42 | beforeSend : function(req) { |
| | 43 | req.setRequestHeader('Authorization', auth); |
| | 44 | } |
| | 45 | }); |
| | 46 | }}} |
| | 47 | |
| | 48 | Thanks to: |
| | 49 | * http://coderseye.com/2007/how-to-do-http-basic-auth-in-ajax.html |
| | 50 | |