Jquery基本身份验证错误
我是 Jquery 的新手。 我正在尝试使用 jquery 发送带有基本身份验证的请求。这就是我所做的。
$.ajax({
type: "GET",
url: domain,
dataType: 'json',
success: function(){
alert('Thanks for your comment!');
},
error:function(){
alert('here');
},
beforeSend: function(xhr){
xhr.setRequestHeader('Authorization', 'Basic ' + encodeBase64(username + ":" + password));
}
});
但我的问题是我没有得到任何反馈。看起来成功或错误方法都被调用了。
在进一步调试时,我得到了
Uncaught ReferenceError: encodeBase64 is not defined
我缺少什么?如有帮助,将不胜感激。
I am a newbie to Jquery.
I am trying to send a request with basic authentication using jquery. This is what i do.
$.ajax({
type: "GET",
url: domain,
dataType: 'json',
success: function(){
alert('Thanks for your comment!');
},
error:function(){
alert('here');
},
beforeSend: function(xhr){
xhr.setRequestHeader('Authorization', 'Basic ' + encodeBase64(username + ":" + password));
}
});
But my problem is I dont get any feedack. Looks like both the success or the error method is called.
On further debugging i get
Uncaught ReferenceError: encodeBase64 is not defined
What am i missing? Help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误表明没有定义名为encodeBase64 的方法。
许多浏览器都有一个从 ascii 到 base64 的内置转换,称为 btoa:
如果您支持较旧的浏览器,请确保有一个 base64 填充,例如 http://ww.w.icodesnip.com/search/javascript%20dark%20codes/45
The error is saying that there is no method called encodeBase64 defined.
Many browsers have a built-in conversion from ascii to base64 called btoa:
If you are supporting older browsers, make sure that there is a base64 polyfill, such as the one at http://ww.w.icodesnip.com/search/javascript%20dark%20codes/45