[英]jQuery $.get not working (Not Found 404)
請幫助我解決一個問題- get
功能不適用於http://wtfismyip.com/text或http://www.passwordrandom.com/query?command=ip
碼:
<span id="global_ip" class="global_ip">global ip - get test</span>
<script type="text/javascript">
$('#global_ip').click(function () {
alert('click!');
$.get({
type: "GET",
url: "http://www.passwordrandom.com/query?command=ip",
dataType: "text"
}).done(function (res) {
alert(res);
}).fail(function (jqXHR, textStatus, errorThrown) {
alert("Call failed: " + textStatus + ", " + errorThrown);
});
});
您無法執行此操作,這違反了相同的來源政策。
由於瀏覽器安全性的限制,大多數“ Ajax”請求都受相同的原始策略約束; 該請求無法從其他域,子域,端口或協議成功檢索數據。
但這可以幫助您實現所需的目標: 使用javascript獲取IP地址
嘗試這個:
<span id="global_ip" class="global_ip">global ip - get test</span>
<script type="text/javascript">
$('#global_ip').click(function()
{
$.get("http://www.passwordrandom.com/query?command=ip", function(data)
{
alert(data);
});
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.