Why, after ajax authorization, does the browser still want the password from the laser?



  • I want to authorise on the user server through js, the axe authorisation works perfectly and redesigns to the right page on which I'm already secured through the aisle, but the browser is requesting logic and password again. How do you avoid that?

    $('#btnlogin').click(function(){
        var username = $("input#userlogin").val();
        var password = $("input#userpassword").val();  
    
    $.ajax
    ({
      type: "GET",
      url: "/cloud/",
      headers: {
        "Authorization": "Basic " + btoa(username + ":" + password)
      },
    
      success: function(){
        console.log('ok');
        setTimeout(function() { window.location = '/cloud/'; }, 2000);
      },
    
      error: function(){
        alert('wrong password');
      }
    });
    

    });



  • The server usually supports the session with the help of cookie. Obviously, your ajax doesn't keep a sessional cookie. In subsequent requests, the server does not find this cookie and will not recognize the client as a logic and password.
    Ajax should remove cookie from the north ' s reply and transmit it to the browser for further use.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2