I have a function like this ..

function1()
{
                if ( valuecboOrganization =="2" )
                    {
                        alert(valuecboOrganization);
                        fnGetDepartmentRequest(valuecboOrganization);
                        return;
                    }
}

function fnGetDepartmentRequest(organizationid)
{	
debugger;
Http.get({url: "../ajax/Process.aspx?organizationid=" + organizationid , asynchronous:false, callback: fnGetDepartmentRequest_callback});
}

function fnGetDepartmentRequest_callback(Result)
{
debugger;
if (Result.readyState==4)
{
if (Result.status==200)// if "OK"
{
fnGetDepartmentRequestProcess(Result);
}
}
}

The Ajax code:

var Http = {  
	ReadyState: 
	{
		Uninitialized: 0,
		Loading: 1,
		Loaded:2,
		Interactive:3,
		Complete: 4
	},
		
	Status: 
	{
		OK: 200,
		
		Created: 201,
		Accepted: 202,
		NoContent: 204,
		
		BadRequest: 400,
		Forbidden: 403,
		NotFound: 404,
		Gone: 410,
		
		ServerError: 500
	},

	Method: {Get: "GET", Post: "POST"},
	
	Asynchronous:true,	
	enabled: false,
	_get: null,	// Reference to the XmlHttpRequest object
	
	
	Init: function(){
		Http._get = Http._getXmlHttp()
		Http.enabled = (Http._get != null)
	},
	
	//condition compilation
	_getXmlHttp: function(){
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
		try 
		{ 
			//alert("Msxml2.XMLHTTP");
			return new ActiveXObject("Msxml2.XMLHTTP"); 
		} 
		catch (e) {} 
		try 
		{ 
			//alert("Microsoft.XMLHTTP");
			return new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (e) {} 
	@end 
	@*/
		try 
		{ 
			//alert("XMLHttpRequest");
			return new XMLHttpRequest();
		}
		catch (e) {}

		return null;
	},

/*	Parameters:
		url: The URL to request. Required.
		callback: onreadystatechange function, called when request is completed. Optional.
		asynchronous: synchronous or asynchonous call : Optional - default : true
		method: HTTP method. Defaults to Method.Get.
*/
	get: function(params, callback_args){	
		if (!Http.enabled){
			//alert("Http: XmlHttpRequest not available.");
			return null;
		}
		
		var url = params.url;
		if (!url)
		{
			//alert("Http: A URL must be specified");
			return null;
		}
				
		var method = params.method || Http.Method.Get;
		var callback = params.callback;
		var async = params.asynchronous;
		//alert(async);
		if (async == undefined)
			async = Http.Asynchronous;

		//alert('method : ' + method + "\n\n" + 'url : ' + url + "\n\n" + 'async : ' + async)
				
		//alert(async);
			
		var sep = (-1 < url.indexOf("?")) ? "&" : "?"	
		url =  url + sep + "__=" + encodeURIComponent((new Date()).getTime());
	
		// Only one request at a time, please
		if ((Http._get.readyState != Http.ReadyState.Uninitialized) && 
			(Http._get.readyState != Http.ReadyState.Complete)){
			this._get.abort();
		}
		alert(method +" Url "+ url+" Async "+ async);
		Http._get.open(method, url, async);
		
		
		
		Http._get.onreadystatechange =  function() {
			if (Http._get.readyState != Http.ReadyState.Complete) return;
			
			if (callback_args == null) callback_args = new Array();

			var cb_params = new Array();
			cb_params.push(Http._get);
			for(var i=0;i<callback_args.length;i++)
				cb_params.push(callback_args[i]);
			
			if ( callback!=null)	
			 callback.apply(null, cb_params);
		}
		//alert(params.body);
		Http._get.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//if (params.body)
		//	Http._get.setRequestHeader("Content-length", params.body.length);
		//Http._get.setRequestHeader("Connection", "close");
		//if (params.body)
		//alert(params.body);
		Http._get.send(params.body || null);
		
	}
	
}

Http.Init()

		function RoleRequest(roleId)
		{	
			Http.get({url: "../ajax/Process.aspx?RoleId=" + roleId , asynchronous:false, callback: RoleRequest_callback});
		}


		function RoleRequest_callback(Result)
		{
			if (Result.readyState==4)
			{
				if (Result.status==200)// if "OK"
				{
					RoleProcessResult(Result);
				}
			}
		}

		function getDom(iXmlStr) 
		{ 
		debugger;
		    if(window.XMLHttpRequest)
		    {
		    	var xmlDoc = new XMLHttpRequest();
    			xmlDoc.loadXML(iXmlStr); 
	    		return xmlDoc; 
		    }
			else if (window.ActiveXObject) 
			{ 
			    var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0"); 
			    xmlDoc.loadXML(iXmlStr); 
			    return xmlDoc; 
			} 
			return (new DOMParser()).parseFromString(iXmlStr, "text/xml");
		}

		function RoleProcessResult(Result)
		{
			try
			{
				var xmlDoc = getDom(Result.responseText); 
				var roleid=0;
				if (xmlDoc.getElementsByTagName("epfroleid").length ==1)
				{
					roleid = xmlDoc.getElementsByTagName("epfroleid")[0].xml;
					roleid = roleid.replace('<epfroleid>', '');
					roleid = roleid.replace('</epfroleid>', '');
				}
				document.getElementById(ctrl_prefix +"cboAssNexRole").value=roleid;
			}
			catch(err)
			{
				//alert(err.description);
			}	
		}

The problem is i cannot able to get the callback to the fnGetDepartmentRequest_callback function.
i.e the fnGetDepartmentRequest_callback is not called after completing the ajax function.

Hi dudes,

The problem for me is that i cannot able to get the callback after calling this line of code,

Http.get({url: "../ajax/Process.aspx?organizationid=" + organizationid , asynchronous:false, callback: fnGetDepartmentRequest_callback});

Also in Ajax code the debugger is not coming inside the code part,

Http._get.onreadystatechange =  function() {
			if (Http._get.readyState != Http.ReadyState.Complete) return;
			
			if (callback_args == null) callback_args = new Array();

			var cb_params = new Array();
			cb_params.push(Http._get);
			for(var i=0;i<callback_args.length;i++)
				cb_params.push(callback_args[i]);
			
			if ( callback!=null)	
			 callback.apply(null, cb_params);
		}

These code works well in IE but it does not work in Mozilla.

i.e i cannot able to get the callback in Mozilla firefox.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.