我正在尝试使用 $.ajax() 从客户端使用主 js 上的以下代码将工作灯应用程序与 datapower 连接起来:
function authDP(username, password) {
$.ajax("http://192.168.44.201:2051/cotizador", {
success : function() {
var invocationData = {
adapter : "B2CAdapter",
procedure : "setUserIdentity",
parameters : [ username, password ]
};
myChallengeHandler.submitAdapterAuthentication(invocationData, {});
alert("Login correcto");
},
error : function(xhr, status, error) {
alert("Failed: " + status + " ; " + error);
},
headers : {
"Authorization" : "Basic "
+ Base64.encode(username + ":" + password)
}
});
}
但是 chrome 控制台返回这个(在 chrome 上):
OPTIONS http://192.168.44.201:2051/cotizador 401 (Unauthorized) wljq.js:8542
OPTIONS http://192.168.44.201:2051/cotizador Origin http://pc-ayi-0204:10080 is not allowed by Access-Control-Allow-Origin. wljq.js:8542
XMLHttpRequest cannot load http://192.168.44.201:2051/cotizador. Origin http://pc-ayi-0204:10080 is not allowed by Access-Control-Allow-Origin.
这在 Firefox 上:
[11:55:22.272] OPTIONS http://192.168.44.201:2051/cotizador [HTTP/1.1 401 Unauthorized 38ms]
标题上是否缺少我的东西?因为在 firefox 控制台/请求/标题/部分我只看到这个:
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0
Origin:http://pc-ayi-0204:10080
Host:192.168.44.201:2051
Connection:keep-alive
Access-Control-Request-Method:GET
Access-Control-Request-Headers:authorization
Accept-Language:es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding:gzip, deflate
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
而且我没有看到基本用户:传递值,这是正确的吗?