JavaScriptで外部サイト(別ドメイン)のファイルを取得しようとすると、crossdomainの制約にひっかかってエラーとなります。
そこでCross-Domain-Ajaxプラグインを使用します。
例:Yahooのトップを取得します。
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript" src="https://github.com/jamespadolsey/jQuery-Plugins/raw/master/cross-domain-ajax/jquery.xdomainajax.js"></script> <script type="text/javascript"> uri = 'http://www.yahoo.co.jp/'; $.get(uri, function(data){ alert(data.responseText); }); </script>
簡単ですね。
おすすめです。
関連エントリー
jQueryによるGoogleサジェストライクなプラグイン【jquery.autocomplete.js】jQueryで画像やリンクのクリック状態(マウスイベント)を強制的に作り出す
jQueryのテンプレートプラグイン【 jQuery.tmpl 】を使用する