dimanche 11 octobre 2015

Javascript- XMLHttpRequest() open method

I understand that with a XMLHttpRequest() open method, we can send uri, user and password. However this uri I have, when I access it in a browser, it prompts a pop up window asking for username and password. Then the user enters name/password in that popup window instead of my user interface.

How should I send the XMLHttpRequest it in this case? The api says it is a GET method. The below code will be triggered by a button. So it's supposed to work like: user press a button, pop up window appears, user enter name/password. Many thanks for your help!

var uri= "someuri that will promotes a dialogue window if I access it in a browser"  //this function will be triggered by a button
var xhr = new XMLHttpRequest();     
xhr.open("GET",uri,true);

xhr.setRequestHeader("Accept", "application/json");

 xhr.onload= function(){
  //how should I do this?
 }    
  xhr.send(null);




Aucun commentaire:

Enregistrer un commentaire