我正在使用advanced-http cordova插件。按照their GitHub repo中的所有步骤进行操作。
但是当我尝试运行我的代码时会弹出一个错误:
缺少必需的“onFail”回调函数
以下是我的代码的样子:
cordova.plugin.http.post('http://127.0.0.1:5000/api/register', {
username: this.username,
password: this.password,
firstname: this.firstname,
middlename: this.middlename,
lastname: this.lastname,
birthday: this.birthday,
age: this.age,
contact: this.contact,
address: this.address,
prisoner: this.prisoner
}, response => {
try {
response.data = JSON.parse(response.data);
// prints test
console.log(response.data.message);
} catch(e) {
console.error('JSON parsing error');
}
}, response => {
// prints 403
console.log(response.status);
//prints Permission denied
console.log(response.error);
});
我在这里缺少什么?请帮忙。
答案 0 :(得分:0)
您的通话中缺少标题参数。根据问题中链接的文档:
获取网址,数据和标题。
cordova.plugin.http.post('http://127.0.0.1:5000/api/register', {
username: this.username,
password: this.password,
firstname: this.firstname,
middlename: this.middlename,
lastname: this.lastname,
birthday: this.birthday,
age: this.age,
contact: this.contact,
address: this.address,
prisoner: this.prisoner
},
{ //your_headers_here
},
response=> {//success callback
},
response=> {//error callback
});