Jaydata& Javascript noobie。我有jaydata和基本身份验证的问题,似乎无法让它工作。我指定用户和密码,但标题从不包含auth行。 Jaydata版本是1.3.6
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="/scripts/jquery-1.11.0.js"></script>
<script type="text/javascript" src="/scripts/datajs-1.0.3.js"></script>
<script type="text/javascript" src="/scripts/jaydata.js"></script>
<script type="text/javascript" src="/scripts/jaydataproviders/oDataProvider.js"></script>
<script type="text/javascript" src="/scripts/zawtst.js"></script>
<script>
var nwcontext = new ZAWTST_SRV.ZAWTST_SRV({
name: 'oData',
oDataServiceHost: 'http://vmerpd01.sap.int:8080/sap/opu/odata/sap/zawtst_srv',
user: "XXXXX",
password: "xxxxxxx"
});
function createItemLI(name, id, css) {
var li = $('<li></li>').append(name).addClass(css).data('id', id);
return li;
}
$(function () {
nwcontext.SalesOrderCollection.toArray(function (SalesOrderCollection) {
SalesOrderCollection.forEach(function (category) {
$('#categories').append(
createItemLI(SalesOrder.SdDoc, SalesOrder.Material, 'category'));
});
});
});
</script>
</head>
<body>
<ul id="categories">
</ul>
</body>
在Chrome中测试时,我看不到任何身份验证行:
Remote Address:10.1.8.171:8080
Request URL:http://vmerpd01.sap.int:8080/sap/opu/odata/sap/zawtst_srv/SalesOrderCollection
Request Method:OPTIONS
Status Code:401 Unauthorized
Request Headers -----------------------
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, maxdataserviceversion, dataserviceversion, authorization
Access-Control-Request-Method:GET
Cache-Control:max-age=0
Connection:keep-alive
Host:vmerpd01.sap.int:8080
Origin:http://10.8.0.6:8080
Referer:http://10.8.0.6:8080/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Response Headers --------------------
content-encoding:gzip
content-length:947
content-type:text/html; charset=utf-8
sap-system:GD1
www-authenticate:Basic realm="SAP NetWeaver Application Server [GD1/400]"
然而,在javascript控制台中我可以看到auth行。
Exception {name: "HTTP request failed", message: "", data: Arguments[1], stack: (...), _getStackTrace: function}
data: Arguments[1]
0: Object
message: "HTTP request failed"
request: Object
callbackParameterName: "$callback"
data: undefined
enableJsonpCallback: false
formatQueryString: "$format=json"
headers: Object
Accept: "application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1"
Authorization: "Basic WFhYWFg6eHh4eHh4eA=="
DataServiceVersion: "2.0"
MaxDataServiceVersion: "2.0"
__proto__: Object
有什么想法吗?
答案 0 :(得分:0)
使用$data.Authentication.BasicAuth
API登录:
httpAuth = new $data.Authentication.BasicAuth.BasicAuth({
username: "XXXXX",
password: "xxxxxxx"
});
context.storageProvider.AuthenticationProvider = httpAuth.CreateRequest({});
httpAuth.Login({
success: function (data) { }
});
<强>参考强>