?實現跨域請求的JavaScript類庫 FlyJSONP
FlyJSONP是一個相當輕量級的JavaScript類庫,使用gzip壓縮后只有1.13kb。它不依賴于任何JavaScript框架,也很方便使用,只需設置一些參數便能夠用它實現跨域的POST和GET請求。

在線演示:http://alotaiba.github.com/FlyJSONP/#!/demo
示例代碼:
<script src="/path/to/flyjsonp.js"></script>
<script>
FlyJSONP.init({debug: true});
//For GET operation
FlyJSONP.get({
url: 'http://storify.com/xdamman.json',
success: function(data) {
console.log(data);
},
error: function(errorMsg) {
console.log(errorMsg);
}
});
//For POST operation
FlyJSONP.post({
url: 'http://storify.com/story/new',
parameters: {
username: 'your-username',
api_key: 'secret-api-key',
title: 'FlyJSONP',
description: 'Testing it out'
},
success: function(data) {
console.log(data);
}
});
</script>
本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!