http://api.fanyi.baidu.com/api/trans/vip/translate?q=apple&from=en&to=zh&appid=2015063000000001&salt=1435660288&sign=f89f9594663708c1605f3d736d01d2d4
我用jquery访问百度翻译接口时
var sign = MD5(str1);
var url = 'http://api.fanyi.baidu.com/api/trans/vip/translate';
$.ajax({url:url,
data: {
"q": query,
"appid": appid,
"salt": salt,
"from": from,
"to": to,
"sign": sign
},
dataType: 'jsonp',
type: 'GET',
success: function (data) {
var r=data.trans_result[0];
mui.alert(r.src+"\n"+r.dst);
},
error:function(xhr,type,errorThrown){
//异常处理;
console.log(type)
}
});
可以返回成功
但是用mui.ajax 时
var sign = MD5(str1);
var url = 'http://api.fanyi.baidu.com/api/trans/vip/translate';
$.ajax(url,{
data: {
"q": query,
"appid": appid,
"salt": salt,
"from": from,
"to": to,
"sign": sign
},
dataType: 'jsonp',
type: 'GET',
success: function (data) {
var r=data.trans_result[0];
mui.alert(r.src+"\n"+r.dst);
},
error:function(xhr,type,errorThrown){
//异常处理;
console.log(type)
}
});
提示
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8020' is therefore not allowed access.
"abort"
5***@qq.com (作者)
2016-07-12 16:43