我想读取的数据的网址是百度云上身份证识别的一个地址:
https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=24.3074598030d473298e5197a463dd4a7f.2592000.1504252081.282335-9863126需要传上的参数是:
id_card_side:front(代表身份证正面)back(代表身份证反面)
image:【图片Base64编码,需encodeURIComponent()】
正常访问参数传正确的数据:
{
"log_id": 525464404,
"words_result_num": 6,
"image_status": "normal",
"words_result": {
"住址": {
"location": {
"width": 337,
"top": 320,
"height": 75,
"left": 176
},
"words": "山东省五莲县城关沿河路398号6号楼3单元205室"
},
"出生": {
"location": {
"width": 0,
"top": 0,
"height": 0,
"left": 0
},
"words": "19871116"
},
"姓名": {
"location": {
"width": 92,
"top": 91,
"height": 33,
"left": 183
},
"words": "权志龙"
},
"公民身份号码": {
"location": {
"width": 444,
"top": 512,
"height": 32,
"left": 341
},
"words": "371121198711160018"
},
"性别": {
"location": {
"width": 0,
"top": 0,
"height": 0,
"left": 0
},
"words": "男"
},
"民族": {
"location": {
"width": 23,
"top": 169,
"height": 28,
"left": 391
},
"words": "汉"
}
}
}我需要识别出来的数据,js的代码怎么去写呢?
https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=24.3074598030d473298e5197a463dd4a7f.2592000.1504252081.282335-9863126需要传上的参数是:
id_card_side:front(代表身份证正面)back(代表身份证反面)
image:【图片Base64编码,需encodeURIComponent()】
正常访问参数传正确的数据:
{
"log_id": 525464404,
"words_result_num": 6,
"image_status": "normal",
"words_result": {
"住址": {
"location": {
"width": 337,
"top": 320,
"height": 75,
"left": 176
},
"words": "山东省五莲县城关沿河路398号6号楼3单元205室"
},
"出生": {
"location": {
"width": 0,
"top": 0,
"height": 0,
"left": 0
},
"words": "19871116"
},
"姓名": {
"location": {
"width": 92,
"top": 91,
"height": 33,
"left": 183
},
"words": "权志龙"
},
"公民身份号码": {
"location": {
"width": 444,
"top": 512,
"height": 32,
"left": 341
},
"words": "371121198711160018"
},
"性别": {
"location": {
"width": 0,
"top": 0,
"height": 0,
"left": 0
},
"words": "男"
},
"民族": {
"location": {
"width": 23,
"top": 169,
"height": 28,
"left": 391
},
"words": "汉"
}
}
}我需要识别出来的数据,js的代码怎么去写呢?
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
<script>
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql',
dataType: 'jsonp',
data: {
q: "select * from json where url=\"http://www.w3dev.cn/json.asp\"",
format: "json"
},
success: function (d) {
alert(JSON.stringify(d))//远程json数据放在query.results下
}
});</script>然后那个data里面的q ,ur=里面我就写我的接口把参数也拼进去啦,然后就是返回没有数据,接口里有个access_token也是通过这个方式获取的,就能返回来值,这个识别的接口怎么就没有值,会不会是image的参数是一张图片的base64编码长度太长了,报错的
哦哦,那这种方式的jsonp代码,对于接口有参数提交的怎么去写呀,url其实长度并不长,参数只能是用&拼接在url里吗,我是这样写才导致它长度长了呀,主要是那个image的参数是图片的base64编码还要encodeURIComponent(),所以有一堆好长好长。我这个是写网页的,html然后要用手机浏览器访问实现,才用到了这个跨域,能有其他js代码实现吗,还必须是跨域的jsonp你既然发布了网站那不是有服务器,用服务做中转,之前说过了。post请求你的服务器发送数据,服务器再发送到百度,服务器获取百度返回值输出,客户端ajax请求你的这个页面,而不是直接请求百度的或者yql,yql的原理也是这样,只是不用经过你的服务器,但是只能get提交,无法post