[英]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.