•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,818 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,048 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 878 | Replies: 3
![]() |
•
•
Join Date: Jul 2008
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
I have a function like this ..
The Ajax code:
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.
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.
•
•
Join Date: Jul 2008
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
Hi dudes,
The problem for me is that i cannot able to get the callback after calling this line of code,
The problem for me is that i cannot able to get the callback after calling this line of code,
JavaScript Syntax (Toggle Plain Text)
Http.get({url: "../ajax/Process.aspx?organizationid=" + organizationid , asynchronous:false, callback: fnGetDepartmentRequest_callback});
Last edited by peter_budo : Jul 14th, 2008 at 7:02 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Jul 2008
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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);
}
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Javascript Problem with Ajax Respons (JavaScript / DHTML / AJAX)
- AJAX generated <select> and FIREFOX (JavaScript / DHTML / AJAX)
- Ajax calls wont work in FireFox! (JavaScript / DHTML / AJAX)
- Inserting dynamic values into Javascript variables (JavaScript / DHTML / AJAX)
- onclick dropdown event (ASP.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Where is event argument in F3
- Next Thread: Disabling Print Screen keypress in IE


Linear Mode