Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript authenticate with htpasswd and fetch json

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

like image 670
Space Bear Avatar asked Feb 21 '26 23:02

Space Bear


1 Answers

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

like image 184
Space Bear Avatar answered Feb 23 '26 12:02

Space Bear



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!