How to request a password protected page in Javascript

I am working on a very simple sidebar gadget to analyze the monthly usage of the router’s bandwidth and determine how far forward or backward I am for this month. The data is located on a password-protected web page on the router (I use DD-WRT, if that matters). I would like to send the page request to the router using Javascript along with all the authentication information in order to get the whole page in one go, but I cannot find the appropriate syntax for this. Any ideas?

Here is my code:

var ua = navigator.userAgent.toLowerCase();
        if (!window.ActiveXObject){
          req = new XMLHttpRequest();
        }else if (ua.indexOf('msie 5') == -1){
          req = new ActiveXObject("Msxml2.XMLHTTP");
        }else{
          req = new ActiveXObject("Microsoft.XMLHTTP");
        }

        req.open('GET', 'http://192.168.1.1/Status_Internet.asp', false, "username", "password");   
        req.send(null);  
        if(req.status == 200){
           dump(req.responseText);
        } else{
            document.write("Error");
        }

        document.write("Second Error");

Firebug indicates that it is an error at req.send(null)- in particular Access to restricted URI denied" code: "1012.

- , , xmlhttpRequest?

+3
4

, iframe, , .

http-auth, http://username:pass@site, , , , .

:

, , http auth, : http://en.wikipedia.org/wiki/Basic_access_authentication, , , javascript, xhr .

+1

Authorization . AJAX, , AJAX. , .

, , .

0

, jQuery .

jQuery $.ajax.

$.ajax({
  url: "path/to/your/page.html", // self-explanatory
  password:"your password", // a string with your password.
  success: function(data){ // on sucsess:
  $("someDiv").html(data); // load in the retrived page
 }
});

. jQuery ajax API.

0

: , , (- ?), Joe X. Schmoe).

, AJAX ( ), : , , 192.168.1.1:80.

- (, PHP script, ) .

0

All Articles