開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Safari、Firefox + Firebug (Webプラウザ、プラグイン)
- JavaScript (プログラミング言語)
- jQuery (JavaScript Library)
Head First JavaScript ―頭とからだで覚えるJavaScriptの基本( Michael Morrison (著), 豊福 剛 (翻訳)、オライリージャパン)の12章(ダイナミックなデータ)、自分で考えてみよう(p.563)を解いてみる。
その他参考書籍
自分で考えてみよう(p.563)
コード(BBEdit)
ajax.js
var AjaxRequest = function () { this.request = null; if (window.XMLHttpRequest) { try { this.request = new XMLHttpRequest(); } catch (e) { this.reques = null; } } else if (window.ActiveXObject) { try { this.reques = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { this.reques = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { this.reques = null; } } } }, pre = document.getElementById('pre0'), ajax_req, url = 'http://mkamimura.com/kamimura_blog/javascript/' + 'head_first_javascript/blog.xml'; AjaxRequest.prototype.send = function (type, url, handler, post_data_type, post_data) { if(this.request !== null) { this.request.abort(); url += "?dummy=" + new Date().getTime(); try { this.request.onreadystatechange = handler; this.request.open(type, url, true); if (type.toLowerCase() === 'get') { this.request.send(null); } else { this.request.setRequestHeader('Content-Type', poast_data_type); this.request.send(post_data); } } catch (e) { alert('サーバとの通信でAjaxエラー\n' + '詳細: ' + e); } } }; ajax_req = new AjaxRequest(); pre.appendChild(document.createTextNode('readyState\n')); ajax_req.send('GET', url, function () { pre.appendChild(document.createTextNode( ajax_req.request.readyState + '\n')); });
0 コメント:
コメントを投稿