JS不能跨域藉助jquery擷取IP地址的方法,jsjquery

來源:互聯網
上載者:User

JS不能跨域藉助jquery擷取IP地址的方法,jsjquery

擷取IP地址,JS也可以擷取用戶端IP地址啦,大家知道JS不能跨域,所以這裡藉助了jquery,真的可以實現擷取IP地址,代碼如下,已通過測試:

<script language="javascript" src="http://www.bkjia.com/jslib/jquery/jquery.js"></script> <script language="javascript"> jQuery(function($){ var url = 'http://chaxun.1616.net/s.php?type=ip&output=json&callback=?&_='+Math.random(); $.getJSON(url, function(data){ alert(data.Ip); }); }); </script>

jquery ajax跨域擷取目前使用者的ip地址及相關資訊,

jquery中有$.ajax方法例如
$.ajax({
url:"answer",
type:"POST"
dataType:"json",
success:callback,
error:error
})
請求answer地址到你後台 在後台獲得使用者ip地址後返回輸出資料流,如果這其中沒有發生錯誤就會進入到callback函數中,你就能得到你需要的值!
 
js跨域訪問js方法,documentdomain="IP地址",怎提示參數無效,大俠解

documen.domain只能嵌套iframe才能跨域。
建議用jsonp方法;
varajaxLogoutScript=document.createElement("script");
ajaxLogoutScript.src=xxxx.url+"?time="+newDate().getTime()+"&jsonCallback=myLogoutcallback";
document.body.appendChild(ajaxLogoutScript);
function myLogoutcallback(data){
if(data){
//dosomething

}

}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.