var HTTP =

{

TYPE_XML: 'XML',

TYPE_TEXT: 'TEXT',

getHTTP: function()

{

var xmlhttp = null;

if(window.XMLHttpRequest)

{

xmlhttp= new XMLHttpRequest();

}

else

{

xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");

}

return xmlhttp;

},

send: function(method, url, callback, dataType)

{

var request= this.getHTTP();

var xml = this.TYPE_XML;

var text = this.TYPE_TEXT;

request.open(method, url, true);

request.onreadystatechange = function()

{

if(request.readyState ===4)

{

var response = null;

var status = request.status;

if(dataType === xml)

{

response = request.responseXML;

}

else if(dataType ===text)

{

response = request.responseText;

}

request = null;

if(status === 200)

{

callback(response);

}

else if(status === 400)

{

alert('올바르지 못한 요청');

}

else if(status === 403)

{

alert('보안문제로 인한 접근 불가');

}

else if (status === 404)

{

alert('페이지를 찾을수 없음');

}

else if(status === 500)

{

alert('서버 오류');

}

else

{

alert('해당 요청이 바르게 처리되지 않음.\nStatusCode: ' + status);

}

}

};

request.send();

},

get: function(url, callback, dataType)

{

this.send('get', url, callback, dataType);

},

post: function(url, callback, dataType)

{

this.send('post', url, callback, dataType);

},

getXML: function(url, callback)

{

this.send('get', url, callback, this.TYPE_XML);

},

postXML: function(url, callback, dataType, dataType)

{

this.send('post', url, callback, this.TYPE_XML);

},

getText: function(url, callback)

{

this.send('get', url, callback, this.TYPE_TEXT);

},

postText: function(url, callback, dataType, dataType)

{

this.send('post', url, callback, this.TYPE_TEXT);

}

};


12-3_XMLHttpRequestStatus.js


반응형

+ Recent posts