Matt Hammond
Matt Hammond

Reputation: 372

How to automatically enter the username in a popup window, ajax?

I have this code which gets a URL, however, the site requires a username to enter. This pops up as a pop-up window. - https://jsfiddle.net/221ztatv/

$.ajax({ 
        type: 'GET',
        url: 'http://www.reed.co.uk/api/1.0/search?keywords=imobilus%20jobs',
        data: { username: 'b110030d-7491-48fe-9354-05c0ec0181d7', password:'' },

However, I want it to automatically fill-in the username and password and submit it, is this possible?

Upvotes: 1

Views: 1178

Answers (1)

bjfletcher
bjfletcher

Reputation: 11508

The same techniques as outlined in this discussion on Stack Overflow can be used.

Either use jQuery's username and password attributes, or the below, with the $.ajax.

beforeSend: function(xhr) {
    xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
};

Bearing in mind that username/password can be read by users. If site is already authenticated, or firewalled/secured internally, then that's better, or this can be for a reason - e.g., the API prohibit server-side authentication. Good luck.

Upvotes: 1

Related Questions