Worklight JavaScript HTTP 适配器无法接收请求数据
Worklight JavaScript HTTP adapter unable to receive request data
我想了解 MFP JSONStore 和 HTTP 适配器的工作原理。我下载了源代码here. I followed the steps to build the app. I also deployed this adapter here。但是当我试图将脏数据推送到适配器时,我注意到了那里。适配器仍然记录未定义。
推送功能代码如下:
function pushToAdapter(){
alert("pushToAdapter");
try {
WL.JSONStore.get(collectionName).push().then(function (res) {
if(Array.isArray(res) && res.length < 1){ // I changed this to res.length > 1
document.getElementById("resultsDiv").innerHTML = "Documents Pushed Successfuly";
} else {
document.getElementById("resultsDiv").innerHTML = "Failed To Push Documents to Adapter: "+ res[0].errorObject;
}
}).fail(function (errorObject) {
alert(errorObject.msg);
});
} catch (e) {
alert("Failed To Push Documents to Adapter");
}
}
& 这是适配器代码:
function pushPeople(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: pushPeople called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function addPerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: addPerson called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function removePerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: removePerson called.');
MFP.Logger.debug('Got data from JSONStore to REMOVE: ' + JSON.stringify(data)); //always undefined
return;
}
请注意,我使用的是 cordova-plugin-mfp-jsonstore 的补丁版本。除了第5238行(如下)外,它与this version相同:
resourceRequest = new WLResourceRequest('adapters/' + invocationData.adapter + '/' + invocationData.procedure, WLResourceRequest.POST);
resourceRequest.setHeader('Content-Type','application/x-www-form-urlencoded'); //patched version
resourceRequest.send().then(ipOpts.onSuccess, ipOpts.onFailure);
看起来参数没有作为推送请求的一部分传递。您可以使用 jsonstore.js 提供的 here 并验证它是否解决了您的问题。这个会在接下来的iFix中正式发布
我想了解 MFP JSONStore 和 HTTP 适配器的工作原理。我下载了源代码here. I followed the steps to build the app. I also deployed this adapter here。但是当我试图将脏数据推送到适配器时,我注意到了那里。适配器仍然记录未定义。
推送功能代码如下:
function pushToAdapter(){
alert("pushToAdapter");
try {
WL.JSONStore.get(collectionName).push().then(function (res) {
if(Array.isArray(res) && res.length < 1){ // I changed this to res.length > 1
document.getElementById("resultsDiv").innerHTML = "Documents Pushed Successfuly";
} else {
document.getElementById("resultsDiv").innerHTML = "Failed To Push Documents to Adapter: "+ res[0].errorObject;
}
}).fail(function (errorObject) {
alert(errorObject.msg);
});
} catch (e) {
alert("Failed To Push Documents to Adapter");
}
}
& 这是适配器代码:
function pushPeople(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: pushPeople called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function addPerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: addPerson called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function removePerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: removePerson called.');
MFP.Logger.debug('Got data from JSONStore to REMOVE: ' + JSON.stringify(data)); //always undefined
return;
}
请注意,我使用的是 cordova-plugin-mfp-jsonstore 的补丁版本。除了第5238行(如下)外,它与this version相同:
resourceRequest = new WLResourceRequest('adapters/' + invocationData.adapter + '/' + invocationData.procedure, WLResourceRequest.POST);
resourceRequest.setHeader('Content-Type','application/x-www-form-urlencoded'); //patched version
resourceRequest.send().then(ipOpts.onSuccess, ipOpts.onFailure);
看起来参数没有作为推送请求的一部分传递。您可以使用 jsonstore.js 提供的 here 并验证它是否解决了您的问题。这个会在接下来的iFix中正式发布