问题
I have an API that generates json, problem is its password protected url, using Apache htpasswd.
how can I authenticate and retrieve the json from javascript, since all methods I have tried give me access deined (I've been using http://username:passwd@urldotcom/path/to/stuff)
Thanks
回答1:
I figured out how to do it.
var something = jQuery.ajax({
type: "GET",
url: url,
username: "user",
password: "password"
});
url is a variable I declared earlier of format http:///path/to/json
来源:https://stackoverflow.com/questions/38458331/javascript-authenticate-with-htpasswd-and-fetch-json