Use basic authentication with jQuery and Ajax

前端 未结 10 1060
野的像风
野的像风 2020-11-21 06:11

I am trying to create a basic authentication through the browser, but I can\'t really get there.

If this script won\'t be here the browser authentication will take o

10条回答
  •  不知归路
    2020-11-21 06:49

    The examples above are a bit confusing, and this is probably the best way:

    $.ajaxSetup({
      headers: {
        'Authorization': "Basic " + btoa(USERNAME + ":" + PASSWORD)
      }
    });
    

    I took the above from a combination of Rico and Yossi's answer.

    The btoa function Base64 encodes a string.

提交回复
热议问题