我正在尝试使用cordova-HTTP插件。每当我尝试调用postJSON()方法时,我都会收到错误
LOG: [ERR] TypeError: cordovaHTTP.postJSON is not a function. (In 'cordovaHTTP.postJSON', 'cordovaHTTP.postJSON' is undefined)
我安装插件时遵循的步骤:
cordova platform add ios
cordova plugin add https://github.com/brendonparker/cordova-HTTP.git
此外,对postJSON方法的调用是在" deviceReady'之后进行的。
谢谢!
答案 0 :(得分:0)
看起来that method被称为postJson
,而不是postJSON
。
以下是如何使用它的示例(copy-pasted from here):
var dto = {
description: 'sending a plain old javascript object',
child: {
foo: 'bar',
}
};
cordovaHTTP.postJson('https://some-server/api/', dto, { }, function(response) {
// prints 200
console.log(response.status);
try {
// response.data has already been parsed
//response.data = JSON.parse(response.data);
// prints test
console.log(response.data.message);
} catch(e) {
console.error('JSON parsing error');
}
}, function(response) {
// prints 403
console.log(response.status);
//prints Permission denied
console.log(response.error);
});
更新: 如果使用Evothings,则必须将插件添加到' evothings'源代码本身,然后重建应用程序。