Skip to content

Instantly share code, notes, and snippets.

@webcyou
Created September 17, 2014 17:08
Show Gist options
  • Save webcyou/cb4c1714e94d0d9146ef to your computer and use it in GitHub Desktop.
Save webcyou/cb4c1714e94d0d9146ef to your computer and use it in GitHub Desktop.
Ajax Model
var AjaxTime = 10000;
var AjaxPath = {
requestFile: "ajaxPath"
};
var AjaxController = function(){};
AjaxController.prototype ={
createHttpRequest: function() {
try {
return newXMLHttpRequest();
} catch(e){}
},
ajaxError: function() { return; },
requestFile: function() {
var that = this,
httpObj = that.createHttpRequest();
var timeout = false,
timer =setTimeout(function(){
timeout = true;
httpObj.abort();
}, AjaxTime);
httpObj.open("POST",AjaxPath.requestFile, true);
httpObj.onreadystatechange = function() {
if(httpObj.readyState !== 4){ return; }
if(timeout) {
that.ajaxError();
return;
};
clearTimeout(timer);
if(httpObj.status == 200){ }
}
httpObj.send(null);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment