XMLHttpRequest を使ってみた
うん、無理。
window.onload = () -> button = document.getElementById 'xhr-btn' button.onclick = () -> image_id = "av5bde" xhr = new XMLHttpRequest() xhr.onreadystatechange = (event) -> if xhr.readyState == 4 if xhr.status == 200 result = document.getElementById 'xhr-result' result.value = xhr.responseText if xhr.status == 0 result = document.getElementById 'xhr-result' result.value = xhr.responseText return xhr.setRequestHeader "Origin", "http://api.twitpic.com/" try xhr.open 'GET', "http://api.twitpic.com/2/media/show.json?id=#{image_id}", true catch error alert error.toString() xhr.send() return return
こんな感じに書いてみたんだけどさ、ダメだった。
ローカルのファイルは読み込めるんだけど、リモートだと、readyState は 4 なのに、status 0 で、
しかも、Firebug では 200 OK だっていう謎の状態が起こる。
\(^o^)/オワタ
2012/12/11 追記
サーバー側であれこれしないといけないらしいので、クライアント側からは何もできない的なことが書いてあった。
アドオン側ではできるのでもーまんたい。