跨域Ajax请求基本身份验证 [英] Cross-domain ajax request basic authentication
本文介绍了跨域Ajax请求基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在做跨域Ajax请求得到一些数据。 REST服务已基本身份验证
(通过 IIS
设置)。
I'm making cross-domain ajax request to get some data. The REST service have Basic authentication
(set through IIS
).
$.ajax({
type: "GET",
xhrFields: {
withCredentials: true
},
dataType: "jsonp",
contentType: "application/javascript",
data: myData,
async: false,
crossDomain: true,
url: "http://xx.xx.xx.xx/MyService/MyService.svc/GetData",
success: function (jsonData) {
console.log(jsonData);
},
error: function (request, textStatus, errorThrown) {
console.log(request.responseText);
console.log(textStatus);
console.log(errorThrown);
}
});
当我提出这个请求时,它提示我输入凭据和放大器;我必须手动输入凭据获得响应。我们可以通过请求本身发送这些凭据?
When I make this request, it prompts me to enter credentials & I have to manually enter credentials to get the response. Can we send those credentials through the request itself?
推荐答案
通行证的用户名和密码,就像下面code,
Pass username and password like following code,
$.ajax({
type: "GET",
xhrFields: {
withCredentials: true
},
dataType: "jsonp",
contentType: "application/javascript",
data: myData,
async: false,
crossDomain: true,
url: "http://xx.xx.xx.xx/MyService/MyService.svc/GetData",
success: function (jsonData) {
console.log(jsonData);
},
error: function (request, textStatus, errorThrown) {
console.log(request.responseText);
console.log(textStatus);
console.log(errorThrown);
}
username: username,
password: password,
});
这篇关于跨域Ajax请求基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文