javascript权限问题

mark_tianxia mark_tianxia 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
function createXmlObj(){
var signatures = ["Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","Msxml2.DOMDocument.3.0","Msxml2.DOMDocument","Microsoft.XmlDom"];
for(var i = 0;i<signatures.length;i++){
try{
var xmlDom = new ActiveXObject(signatures[i]);
}catch(e){
//忽略错误,继续测试下一个版本
}
}

return xmlDom.xml;
}

/*
创建XMLHttpRequest请求对象
*/
function createXMLhttp(){
var xmlhttp;
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
try{
xmlhttp = new XMLHttpRequest();
}catch(e){}
}
}
return xmlhttp;
}

function sendInfor(phe){

var XmlObj = createXmlObj();
//alert(XmlObj);
//根据不同的浏览器创建不同的XMLHttpRequest对象
var xmlhttp = createXMLhttp();

//alert(url);
//创建一个请求

xmlhttp.open("get","http://opendata.baidu.com/api.php?query="+phe.value+"&co=&resource_id=6004&t="+phe.value+"&ie=utf8&oe=gbk&cb=bd__cbs__xecpzm&format=json&tn=baidu",false);

//设置请求的HTTP头
//xmlhttp.setRequestHeader("Content-Type"," application/utf-8 ");
xmlhttp.setRequestHeader("Content-Type","application/json;charset=gbk");
xmlhttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; MDDC; .NET4.0C; .NET4.0E; 360SE)");
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4){
//alert("发送成功!");
}
}
//发送请求
xmlhttp.send();
var aa = xmlhttp.ResponseText;//得到后台传递过来的text文本信息
//var test =xmlhttp.responseStream;//得到后台传递过来的输入流信息--一般不用
var first;
var type;
if(aa.indexOf("prov"+'"'+":"+'"'+'"') == -1)
{
first=aa.indexOf("prov"+'"'+":"+'"');
type=aa.substring(first+7,first+10);
type=type.replace('"',"");
}
else
{
first=aa.indexOf("city"+'"'+":"+'"');
type=aa.substring(first+7,first+9);
}
first=aa.indexOf("type"+'"'+":"+'"');
var yun=aa.substring(first+9,first+11);
alert(type+yun);
alert(aa);
}
这
xmlhttp.open("get","http://opendata.baidu.com/api.php?query="+phe.value+"&co=&resource_id=6004&t="+phe.value+"&ie=utf8&oe=gbk&cb=bd__cbs__xecpzm&format=json&tn=baidu",false);
段代码报错权限问题,开发都没有问题。放到服务器 就报错。。
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
mark_tianxia
JavaScript 87,984 成员 224,681 内容