my.getbackgroundfetchdata(object object)
基础库 或更高版本; 且 支付宝客户端 10.2.36 或更高版本; 若版本较低,建议采取 兼容处理 。
支小宝客户端 支持
安诊儿客户端 支持
小程序开发者工具: 支持。推荐在 ide 3.0.0 及以上版本调用该 api,在旧版 ide 上调用该 api 将可能报错。
主体: 企业支付宝小程序 、 个人支付宝小程序
拉取 backgroundfetch 客户端缓存数据。
object object
查看示例
属性 | 类型 | 默认值 | 必填 | 描述 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fetchtype | string | - | 是 | 预加载类型 |
||||||||||
|
||||||||||||||
success | function | - | 否 | 调用成功的回调函数 |
||||||||||
fail | function | - | 否 | 调用失败的回调函数 |
||||||||||
complete | function | - | 否 | 调用结束的回调函数(调用成功、失败都会执行) |
success 回调函数
参数
object res
属性 | 类型 | 描述 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
fetchtype | string | 预加载类型 |
||||||||||
|
||||||||||||
timestamp | number | 预加载数据的时间戳,单位:ms |
||||||||||
fetcheddata | object | 预加载的数据 |
fail 回调的参数为 object,error
属性为错误码,errormessage
属性为错误消息。
错误码 | 错误消息 | 凯发app官方网站的解决方案 |
---|---|---|
2 | invalid parameter! |
检查入参的正确性和有效性。 |
3 | 没有预加载数据。 |
检查 preload.json 配置是否正确,以及预拉取对应的能力(my.request 或 my.getlocation)在小程序中是否可以正常调用并返回数据。 |
5 | 用户未授权调用jsapi:my.getlocation |
先通过正常(非预拉取)方式调用对应的 api(如 my.getlocation),取得用户授权。 |
my.getbackgroundfetchdata({
fetchtype: 'pre',
success: function(res) {
console.log(res);
},
fail: function(err) {
console.log(err);
}
});
{
"fetchtype": "pre",
"fetcheddata": {
"data": {
"data": "测试数据"
},
"error": 0,
"headers": {
"access-control-allow-methods": "delete,put,post,get,options",
"access-control-allow-origin": "*",
"connection": "keep-alive",
"content-encoding": "gzip",
"content-type": "application/json; charset=utf-8",
"date": "tue, 03 jan 2023 06:19:43 gmt",
"etag": "w/\"17-fcilbcxif16dtdtgymim e2ycse\"",
"param_req_size": "0",
"param_res_size": "0",
"param_retry": "f",
"param_traffic": "0",
"server": "openresty/1.11.2.5",
"transfer-encoding": "chunked",
"x-mass-provider": "hc",
"x-mass-reuselink": "t",
"x-powered-by": "express",
"x-wait-timing": "26"
},
"status": 200,
"timestamp": 1672726783548
},
"timestamp": "1672726783548"
}
{
"fetchtype": "jsapipre",
"fetcheddata": {
"accuracy": 30,
"altitude": 0,
"bearing": 0,
"city": "杭州市",
"cityadcode": "330100",
"country": "中国",
"countrycode": "156",
"district": "西湖区",
"districtadcode": "330106",
"latitude": 30.133066,
"locationtime": 1673332556837,
"locationtype": "wifi",
"longitude": 120.079511,
"province": "浙江省",
"provinceadcode": "330000",
"speed": 0
}
}
{
"error": 3,
"errormessage": "没有预加载数据"
}