4

When I work from home, URLs to our development servers require basic authentication. So, if a web page has a script or link tag reference to our development server, we get a prompt for each of those server URLs.

Recently, I wrote an ajax call to an API on the development server using jQuery $.ajax. I do not get the authentication prompt, and Firebug reports 401 unauthorized. However, if I put this API directly in the browser address bar, I get the prompt.

Currently, I have to switch to Chrome and invoke --disable-web-security. When I do that, the $.ajax call will cause the browser to give me a prompt.

Is this a "problem" with $.ajax() or the browser or something else?

Liam
  • 27,717
  • 28
  • 128
  • 190
Stephen
  • 2,410
  • 3
  • 33
  • 57
  • 1
    Solution already exists: http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax – Garfield Mar 07 '13 at 17:37

1 Answers1

1

You could send your credentials along with the request as suggested in the docs of jQuery.ajax():

$.ajax({
    // ...
    username: "foo",
    password: "bar"
});

make sure you're not pushing your personal credential to some SCM, though!

rodneyrehm
  • 13,442
  • 1
  • 40
  • 56