| 출력문자 인코딩 변경 (0) | 2010/02/20 |
|---|---|
| 세션확인후 없으면 이동 (0) | 2010/02/20 |
| 배열의 특정 원소를 삭제 (0) | 2010/02/17 |
| 출력문자 인코딩 변경 (0) | 2010/02/20 |
|---|---|
| 세션확인후 없으면 이동 (0) | 2010/02/20 |
| 배열의 특정 원소를 삭제 (0) | 2010/02/17 |
/*
기본 사용법
var Obj = new Class_Ajax("GET","./gogo.php",true);
Obj.SetGetValue("&name=심재성");
Obj.CallBack(requestFucntion);
Obj.Start();
function requestFucntion()
{
if(Obj.OnComplete())
{
alert(Obj.request.responseText);
}
}
*/
Class_Ajax = function(ctype,curl,csync)
{
var Url; //요청할 파일 경로
var request ; //요청객체
var sync ; //동기/비동기(true,false)
var type ; //전송방식(GET,POST)
var PostValue; //post로 전송할 값
var GetValue; //get으로 전송할 값
var isCallBack; //콜백함수 설정 여부(true,false)
//---------클래스 초기화
this.type = ctype;
this.Url = curl;
this.sync = csync;
this.isCallBack = false;
this.request = this.CreateRequest()
}
//Ajax 요청의 상태가 수신완료 상태인지 확인
Class_Ajax.prototype.OnComplete = function()
{
if(this.request.ReadyState == 4)
{
if(this.request.status == 200)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
//get 으로 전송할 변수 지정 함수
Class_Ajax.prototype.SetGetValue = function(value)
{
this.GetValue = value;
}
//요청방식 지정 함수
Class_Ajax.prototype.SetType = function(type)
{
this.type = type;
}
//요청 시작 함수
Class_Ajax.prototype.Start = function()
{
if(!this.isCallBack)
{
alert("객체명.CallBack(콜백함수명) 을사용해 콜백 함수를 설정 하세요");
return false;
}
if(this.type=="GET")
{
this.SendRequestGet();
}
else
{
this.SendRequestPost();
}
}
//Ajax 요청 객체 생성함수
Class_Ajax.prototype.CreateRequest = function()
{
try
{
this.request = new XMLHttpRequest();
}
catch (tryMicrosoft)
{
try
{
this.request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (otherMicrosoft)
{
try
{
this.request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed)
{
this.request = null;
}
}
}
if(this.request != null)
{
return this.request;
}
else
{
return false;
}
}
//get방식 전송
Class_Ajax.prototype.SendRequestGet = function()
{
this.request.open(this.type,this.Url+ "?dumy="+new Date().getTime() +this.GetValue,this.sync);
this.request.send(null);
}
//post방식 전송
Class_Ajax.prototype.SendRequestPost = function()
{
this.request.open(this.type,this.Url+ "?dumy="+ new Date().getTime(),this.sync);
this.request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
this.request.send(this.PostValue);
}
//콜백함수 지정 함수
Class_Ajax.prototype.CallBack = function(Func)
{
this.request.onreadystatechange = Func;
this.isCallBack = true;
}
| Ajax 기본처리 클래스 ( 구현중 저장 ) (0) | 2010/02/19 |
|---|---|
| Ajax 요청 객체 생성 (0) | 2010/02/19 |