title: How to make a Javascript JSON Request to an API that requires authentication
body: <p>I am currently building a website that uses data from a JSON based REST API. I need to retrieve a JSON file from a specific URL but I am struggling with how to access it because the API requires a username and password.</p>
  
  <p>I have a javascript variable containing the url that I need to get the data from, as well as the correct username and password. I just dont know how to put it all together to make a request.</p>
  
  <p>-</p>
  
  <p>Alternatively, I have managed to find a php class that very easily and simply returns PHP arrays for all the data i need. I simply append my username and password inside a php file and the class takes care of the rest. This maybe an easier way to access the JSON rather than using javascript? However I have no idea how I can pass a javascript URL variable into it. </p>
  
  <p>Thanks a lot for your help. I hope i've made my problem clear!</p>