这是来自 odatajs git 存储库的测试用例,希望对您有所帮助:
var headers = { "Content-Type": "application/json", Accept: "application/json" };
var request = {
requestUri: "http://<wwww bla bla .com>/endpoints/FoodStoreDataServiceV4.svc/Foods",
method: "GET",
headers: headers,
data: null
};
odatajs.oData.request(request, function (data, response) {
if ((response.statusCode == '200') &&
(response.body.indexOf('}', response.body.length - 1) == response.body.length - 1) &&
response.headers['Content-Type'] == "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8") {
document.getElementById('msg').innerHTML += ("<div>odatajs V4 testing pass!</div>");
} else {
document.getElementById('msg').innerHTML += ("<div>odatajs V4 testing failed.</div>");
}
}, function (err) {
document.getElementById('msg').innerHTML += ("<div>odatajs V4 testing failed.</div>");
});