Re: [問題] 如何使用 jQuery.parseJSON

看板Ajax作者 (藍藍紫黃橘 粉灰白綠咖)時間13年前 (2010/12/25 00:47), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《gaekeamql (芋頭)》之銘言: : JSON 不能跨SERVER 只能用JSONP : $.getJSON("http://xxxxx/index.php?callback=?", : function(data){ : }); 這句話不太對 應該是說jquery getJSON只能用JSONP跨網域 JSON是可以用來跨網域的 常見的方法是事先載入或動態載入一段<script src="" rel="nofollow">http://"></script> (jQuery可用getScript跨網域載入js) 這段script隨便server端愛怎麼寫就怎麼寫  而client端只要知道回傳值 就可以很方便的拿來應用 以歌詞API為例 http://lyrics.wikia.com/LyricWiki:REST 可寫成json song = { 'artist':'Slipknot', 'song':'Before I Forget', 'lyrics':'Go!\n\nStapled shut - Inside an outside world and I\'m\nSealed', 'url':'http://lyrics.wikia.com/Slipknot:Before_I_Forget' } 或js function function lyricwikiSong(){ this.artist='Slipknot'; this.song='Before I Forget'; this.lyrics='Go!\n\nStapled shut - Inside an outside world and I\'m\nSeale'; this.url='http://lyrics.wikia.com/Slipknot:Before_I_Forget'; } var song = new lyricwikiSong(); 以上兩個跨網域的方法 雖然不是常見的jsonp形式 但一樣有著jsonp的精神 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.122.30.198

12/25 01:37, , 1F
恩恩!! 其實都是jsonp 都是載入一個 javascript
12/25 01:37, 1F
文章代碼(AID): #1D5Cw48M (Ajax)
文章代碼(AID): #1D5Cw48M (Ajax)