1

I have follow script:

var username_my = 'my_useraname';
var password_my = 'my_password';  

function make_base_auth(username_my, password_my) {
  var tok = username_my + ':' + password_my;
  // first try, without success
  // var hash = btoa(tok); 
  var hash = base64.encode(tok);
  return "Basic " + hash;
}     
var xhr = null;
try {
   xhr = new XMLHttpRequest();
} catch (e){
   try{
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e){
      try{
         xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
         xhr = null;
      }
   }
}
$.ajax({
    type: "GET",
    url: "https://...",
    dataType: 'json',
    async: false,
    error: function(xhr, status, error) {
              alert("error: "+error+"\n"+status);
            },
    data: { "parameter": "1", "format":"json" },
// try - 1, fail
    // headers: {"Authorization": "Basic " +username_my +":" +password_my},    
// try - 2, fail
    // beforeSend: function (xhr){ 
        // xhr.setRequestHeader('Authorization', make_base_auth(username_my, password_my)); 
    // },
// try – 3, fail
    username: username_my,
    password: password_my,
    success: function (status){
        alert('Thanks for your comment! '+status); 
    }

}).fail(function( status) {
    var aus = "";
    jQuery.each(status, function(i, v){
        aus += i+",\t\t "+v+"\n";
    });
    alert( aus );
}).done(function( status) {
    alert( status );
});

And I can’t authorize to the server. From the scritp I get follow error message: First errow-alert:

error: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 >(NS_ERROR_DOM_BAD_URI)" location : ". to jquery ..jquery-1.11.1.js?v=131209 >Line: 9631"] error

Second-alert:

... } responseJSON, undefined status, 0 statusText, [Exception... "Access to restricted URI denied" code: "1012" >nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "...jquery/jquery-1.11.1.js?>v=131209 Line: 9631"]

I use jQuery 1.11.1

If I give you my URL in the browser, I get authorization windows, wearing there logon credentials and data from server are returned.

I tried three different authentication types, with no it worked Does anyone have an idea what the fault lies with the authentication?

regards

Prophet
  • 32,350
  • 22
  • 54
  • 79
webuser57
  • 171
  • 2
  • 9

0 Answers0