Iev*_*ida 2 javascript authentication ajax jquery
我正在尝试向ajax请求添加标头.
我使用setRequestHeader但它什么都不做.我可以在firefox中查看请求标头不包含身份验证!我做错了什么?
以及如何添加标题?
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://test/test.svc/news",
dataType: "json",
beforeSend : function(xhr) {
xhr.setRequestHeader("Authentication", "Basic " + Base64.encode(username + ":" + password))
},
success: function(data) {
alert('Success');
},
error: function() {
alert("Loading data error...");
}
});
}
Run Code Online (Sandbox Code Playgroud)
请尝试用户名和密码
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://test/test.svc/news",
dataType: "json",
username: 'username', /* not user */
password: 'pass',
success: function(data) {
alert('Success');
},
error: function() {
alert("Loading data error...");
}
});
}
Run Code Online (Sandbox Code Playgroud)
username - 用于响应HTTP访问身份验证请求的用户名
归档时间: |
|
查看次数: |
2311 次 |
最近记录: |