在我的应用程序中,我通过表单保存数据并调用 Api 进行相同的操作,为了检查它们的互联网连接是否缓慢,我在 ionic2 中使用超时,如下所示:
savedata(){
let headers = new Headers();
headers.set('Content-Type', 'application/x-www-form-urlencoded')
this.http.post(`api-url to save data`, "access_token=" + access_token + "&user_id=" + id + "&username=" + username, { headers: headers }).timeout(30000).map(res => res.json()).subscribe(data => {
if(data.status == 200)
{
console.log("data saved.");
}
else
{
console.log("Error saving data.");
}
},error => {
// if their is an internet issue
// on timeout
this.response_message = 'Internet connection error. Please try again.';
});
}
当表单提交时,会触发 savedata() 函数。
提前致谢。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)