麻煩幫我看看
<<!DOCTYPE html>
<html>
<head>
?? ?<meta charset="UTF-8">
?? ?<title>iptaobao</title>
</head>
<body>
?? ?<h1>查詢ip</h1>
?? ?<label>請(qǐng)輸入查詢的ip:</label>
<input type="text" id="keyword" />
<button id="search" onClick="taobao()">查詢</button><br/>
<label>ip的信息為:</label><br/>
<p id="searchResult"></p>
<script type="text/javascript">
function taobao(){
var request=new XMLHttpRequest();
request.open("Get","http://iptaobao.com/service/getlpInfo.php?ip="+document.getElementById("keyword").value);
request.send();
request.onreadystatechange=function(){
?? ?if(request.readyState===4&&request.status===200){
????????? document.getElementById("searchResult").innerHTML=request.responseText;
?? ?}
?? ?else
?? ??? ?alert("發(fā)生錯(cuò)誤"+request.status);
}
}
</script>
</body>
</html>
得不到想要的結(jié)果,出現(xiàn)已攔截跨源請(qǐng)求:同源策略禁止讀取位于 http://iptaobao.com/service/getlpInfo.php?ip= 的遠(yuǎn)程資源。(原因:CORS 頭缺少 'Access-Control-Allow-Origin')。請(qǐng)問要怎么解決。
2016-12-04
"http://iptaobao.com/service/getlpInfo.php?ip=61.139.139.139 ?獲取不了值
2016-12-21
你這個(gè)屬于跨域請(qǐng)求,就是你所請(qǐng)求的資源不是你自己服務(wù)器上的,解決這個(gè)問題可以用jaonp或者新建script標(biāo)簽來解決。而且就算在同域內(nèi),你的后臺(tái)服務(wù)器沒有為你現(xiàn)在寫的東西留下接口,也是無法請(qǐng)求到的。
2016-12-04
是因?yàn)榉?wù)端后臺(tái)設(shè)置是嗎
2016-12-04
沒有試過 ? 是不是request.open和request.send()之間少了請(qǐng)求頭:request.setRequestHeader("Content-type","application/x-www-form-urlencoded");