为方便前端用户使用挖数据接口,本文介绍使用jsonp进行接口调用方法。
一、返回格式选择json 类型
二、添加一个名为参数 jsonp_callback 参数,值以字母开头时间戳结果,例如:jsonp_callback=callback1647397359
三、部分插件的jquery带的其它任意参数,会影响签名,导致签名不过,使用以下办法解决。
1. 使用hash方式验证,
2. 使用自定义的jsonp函数。可以参与这个 https://www.wapi.cn/js/wapi_jsonp.js
调用方式:
wapi_jsonp({
"url":'https://www.wapi.cn/ajax/get_md5', // 请求地址
"jsonp":"callback"+parseInt(new Date().getTime()/1000),
"data": {'test':'true'},
success:function(res){ // 请求成功的回调函数
if(res != null){
console.log("跨域请求成功!");
console.log(res)
}
},
error: function(error) {
console.log(error)
} // 请求失败的回调函数*/
})