jsonp跨域原理

來源:互聯網
上載者:User

標籤:lang   http   屬性   .com   net   src   lan   動態   建立   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<input type="button" value="點擊請求">
<script src="jquery.min.js"></script>
<script>
function my(data){
console.log(data);
}
// 動態建立script標籤添加到頁面上,src屬性請求百度的地址,可以在network中看到請求的響應,這個響應有個很長的名字,J135itpo6i(裡面是請求地址響應給我們的資料) ,所以我們就可以將這個名字改成我們自己定義的方法函數,my&_=1478414579187"這裡邊的my就是我們自己定義的那個函數,所以我們可以自己定義這個函數,然後console.log輸出一下,用於操作我們請求過來的資料
$(function(){
var sc = document.createElement("script");
sc.setAttribute("src","https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=1&sugmode=2&json=1&p=3&sid=1459_21106_18559_17001_20698_21455_21395_21377_21191_20718&req=2&bs=1&pbs=1&csor=1&pwd=1&cb=my&_=1478414579187");
document.body.appendChild(sc);
})
</script>
</body>
</html>

jsonp跨域原理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.