diff --git a/README.md b/README.md index 306a101..edb7f18 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ --------------------------------------------------------------------------------

Javascript代码

Version 1.0.0
- Author:scott (吴超武)
+ Author:scott
有什么疑问和建议请发邮箱至Email:wchaowu@gmail.com
github: https://github.com/wchaowu/
本人积累的一些javascript的写法,参考了dhtmlx套件框架,javascript设计模式书籍、Jquery源代码,QQ空间、webQQ和新浪微博。 diff --git a/index.html b/index.html index a9a6c0d..315ce10 100644 --- a/index.html +++ b/index.html @@ -1,62 +1,35 @@ - - - - - - -var SimpleHandler = function() {}; // implements AjaxHandler -SimpleHandler.prototype = { - request: function(method, url, callback, postVars) { - var xhr = this.createXhrObject(); - xhr.onreadystatechange = function() { - if(xhr.readyState !== 4) return; - (xhr.status === 200) ? - callback.success(xhr.responseText, xhr.responseXML) : - callback.failure(xhr.status); - }; - xhr.open(method, url, true); - if(method !== 'POST') postVars = null; - xhr.send(postVars); - }, - createXhrObject: function() { // Factory method. - var methods = [ - function() { return new XMLHttpRequest(); }, - function() { return new ActiveXObject('Msxml2.XMLHTTP'); }, - function() { return new ActiveXObject('Microsoft.XMLHTTP'); } - ]; - - for(var i = 0, len = methods.length; i < len; i++) { - try { - methods[i](); - } - catch(e) { - continue; - } - // If we reach this point, method[i] worked. - this.createXhrObject = methods[i]; // Memoize the method. 记住该方法 - return methods[i](); - } - - // If we reach this point, none of the methods worked. - throw new Error('SimpleHandler: Could not create an XHR object.'); - } -}; - -/* Usage. */ - -var myHandler = new SimpleHandler(); -var callback = { - success: function(responseText) { alert('Success: ' + responseText); }, - failure: function(statusCode) { alert('Failure: ' + statusCode); } -}; -myHandler.request('GET', 'script.php', callback); - -​ - - \ No newline at end of file + + +