Click here to Skip to main content
15,909,193 members
Home / Discussions / Web Development
   

Web Development

 
AnswerRe: CryptImportKey Pin
Paddy Boyd28-Apr-06 1:14
Paddy Boyd28-Apr-06 1:14 
QuestionCheck Size of Uploaded File Pin
thainam26-Apr-06 21:57
thainam26-Apr-06 21:57 
AnswerRe: Check Size of Uploaded File Pin
Guffa26-Apr-06 22:38
Guffa26-Apr-06 22:38 
QuestionI want to change internet options Pin
shortwave26-Apr-06 5:13
shortwave26-Apr-06 5:13 
AnswerRe: I want to change internet options Pin
Shog926-Apr-06 19:43
sitebuilderShog926-Apr-06 19:43 
QuestionJavascript OOP Pin
CoolASL26-Apr-06 2:02
CoolASL26-Apr-06 2:02 
AnswerRe: Javascript OOP Pin
Shog926-Apr-06 19:37
sitebuilderShog926-Apr-06 19:37 
GeneralRe: Javascript OOP Pin
CoolASL28-Apr-06 4:57
CoolASL28-Apr-06 4:57 
Hi Shog,
Thanks for the reply.

I am not sure if the way you suggested would work.
I am using function MyClass(){....} type declaration to declare my class. So, if i want to assign the readystatechange for a particular object, i think, i'll have to use something like
this.xmlHttpObj.readystatechange = this.MonitorStateChange;

Can you please tell me more about the way you have written above. Any reference where i can learn more about it.

Here's my code... I'll highly appreciate it if you can give me some pointers.
Thanks in advance.

function AJAXFramework(OnCompFunc) //The AJAXFramework class
{
	//Four methods for the 4 possible states
	this.OnLoading = null;     // 1
	this.OnLoaded = null;      // 2
	this.OnInteractive = null; // 3
	this.OnCompleted = OnCompFunc;   // 4
	this.SendRequest = SendRequest;
	this.xmlHttp = null;//GetXmlHttpObject(); // To be initialized when SendRequest() is called

	//other member functions
	this.SendRequest = SendRequest;
	this.MonitorStateChange = MonitorStateChange;
	
	alert("OnCompleted = " + this.OnCompleted);
	alert(this.xmlHttp);
	
	function SendRequest(strURL, strType, strParams)
	{
		//strURL    : the url to be contacted
		//strType   : Request type. Can have only one of the following:
		//            "GET", "POST"
		//strParams : if request type is POST, then parameters that 
		//            should be sent.
		
		//abort any ongoing request
		if (this.xmlHttp != null && this.xmlHttp.readyState != 0 && this.xmlHttp.readyState != 4)
		{
			this.xmlHttp.abort();
		}

		//Get the XMLHttp object
		xmlHttp = GetXmlHttpObject();
		
		//Set the event listener
		xmlHttp.onreadystatechange = this.MonitorStateChange;

		//alert("calling...");
		//this.MonitorStateChange();

		
		if (strURL.length > 0)
		{
			if(strType == "GET")
			{
				xmlHttp.open("GET", strURL , true);
				xmlHttp.send(null);
			}
			else
				if(strType == "POST")
				{
					xmlHttp.open("POST", strURL, true);
					xmlHttp.send(strParams);
				}
				else
				{
					alert("Request type has not been specified properly.\nRequest types can be GET or POST only.");
				}
		}
	}
		
	function MonitorStateChange()
	{
		//alert(AJAXFramework.OnCompleted);
		//alert(this.readyState);
		alert("OnCompleted = " + this.OnCompleted);
		//alert(arguments.length);
		if(this.xmlHttp.readyState == 1)
		{
			if(this.OnLoading != null)
			{
				OnLoading();
			}
			return;
		}

		if(this.xmlHttp.readyState == 2)
		{
			if(this.OnLoaded != null)
			{
				OnLoaded();
			}
			return;
		}

		if(this.xmlHttp.readyState == 3)
		{
			if(this.OnInteractive != null)
			{
				OnInteractive();
			}
			return;
		}

		if (this.xmlHttp.readyState == 4 || this.xmlHttp.readyState == "complete")
		{
			//alert("State = 4 \n" + this.OnCompleted);
			if(this.OnCompleted != null)
			{
				alert(xmlHttp.responseText);
				this.OnCompleted();
			}
			
			return;
		}
	}
	
	function GetXmlHttpObject()
	{
		alert("Getting xml obj");
		var objXmlHttp=null
	
		if (navigator.userAgent.indexOf("Opera")>=0)
		{
			alert("This example doesn't work in Opera");
			return;
		}
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{
			var strName="Msxml2.XMLHTTP";
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP";
			}
			try
			{
				objXmlHttp=new ActiveXObject(strName);
				//objXmlHttp.onreadystatechange=handler ;
				return objXmlHttp;
			}
			catch(e)
			{
				alert("Error. Scripting for ActiveX might be disabled");
				return ;
			}
		}
		if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			objXmlHttp=new XMLHttpRequest();
			objXmlHttp.onload=handler;
			objXmlHttp.onerror=handler ;
			return objXmlHttp;
		}
	}
	

}



*** Who said nothing is impossible? I have been doing it for a long time ***

QuestionPankaj Pin
rizwan.afsar25-Apr-06 21:52
rizwan.afsar25-Apr-06 21:52 
GeneralRe: Pankaj Pin
Guffa25-Apr-06 22:34
Guffa25-Apr-06 22:34 
GeneralRe: Pankaj Pin
Vasudevan Deepak Kumar26-Apr-06 18:32
Vasudevan Deepak Kumar26-Apr-06 18:32 
GeneralRe: Pankaj Pin
Sushant_Mathur26-Apr-06 23:30
Sushant_Mathur26-Apr-06 23:30 
GeneralRe: Pankaj Pin
rizwan.afsar27-Apr-06 0:05
rizwan.afsar27-Apr-06 0:05 
GeneralRe: Pankaj Pin
rizwan.afsar27-Apr-06 0:14
rizwan.afsar27-Apr-06 0:14 
GeneralRe: Pankaj Pin
Guffa27-Apr-06 0:46
Guffa27-Apr-06 0:46 
GeneralRe: Pankaj Pin
Sushant_Mathur27-Apr-06 1:11
Sushant_Mathur27-Apr-06 1:11 
GeneralRe: Pankaj Pin
Vasudevan Deepak Kumar27-Apr-06 19:52
Vasudevan Deepak Kumar27-Apr-06 19:52 
QuestionASP page always displays Old File content. Pin
BlrBoy25-Apr-06 20:15
BlrBoy25-Apr-06 20:15 
AnswerRe: ASP page always displays Old File content. Pin
Guffa25-Apr-06 20:44
Guffa25-Apr-06 20:44 
AnswerRe: ASP page always displays Old File content. Pin
alexey N25-Apr-06 22:36
alexey N25-Apr-06 22:36 
GeneralRe: ASP page always displays Old File content. Pin
BlrBoy26-Apr-06 0:31
BlrBoy26-Apr-06 0:31 
GeneralRe: ASP page always displays Old File content. Pin
alexey N26-Apr-06 0:42
alexey N26-Apr-06 0:42 
GeneralRe: ASP page always displays Old File content. Pin
BlrBoy26-Apr-06 1:05
BlrBoy26-Apr-06 1:05 
GeneralRe: ASP page always displays Old File content. Pin
alexey N26-Apr-06 17:38
alexey N26-Apr-06 17:38 
AnswerRe: ASP page always displays Old File content. Pin
Vasudevan Deepak Kumar27-Apr-06 4:24
Vasudevan Deepak Kumar27-Apr-06 4:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.