ivirabyan / jquery-mentions

Adds mentioning support to your text fields.
http://ivirabyan.github.io/jquery-mentions/
MIT License
114 stars 49 forks source link

Add authorization header on ajax request #50

Closed shivamsinha15 closed 8 years ago

shivamsinha15 commented 8 years ago

hi I was wondering if there was anyway to add authorization header on ajax request ?

ivirabyan commented 8 years ago

Yes, you can accomplish this by defining custom function for fetching data from server:

$('textarea').mentionsInput({
    source: function(request, callback) {
        $.get({
            url: 'http://example.com',
            data: {term: request.term},
            success: callback,
            beforeSend: function (xhr) {
                xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password));
            }
        });
    }
});