1

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?

shammelburg
  • 6,974
  • 7
  • 26
  • 34
Matt Hammond
  • 372
  • 2
  • 11

1 Answers1

1

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.

Community
  • 1
  • 1
bjfletcher
  • 11,168
  • 4
  • 52
  • 67