Stephen
Stephen

Reputation: 2570

Lack of an authentication prompt for secured URLs if requested through $.ajax

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?

Upvotes: 4

Views: 800

Answers (1)

rodneyrehm
rodneyrehm

Reputation: 13557

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!

Upvotes: 1

Related Questions