rekha Posted December 21, 2007 Share Posted December 21, 2007 Hi I am having a customer list page.I have a delete button using anchor tag.If I want to delete a customer an alert should come and if the customer is having a pending invoice then one more alert should come.I have written this using ajax page by getting customer id. function Isconfirm(id) { var aid = id; var http_request = false; var s; if (window.XMLHttpRequest) // For Mozilla, Safari,... http_request = new XMLHttpRequest(); else if (window.ActiveXObject) // For IE { try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Giving up Cannot create an XMLHTTP instance)'); return false; } http_request.onreadystatechange = function() {s=alertContents(http_request); }; http_request.open('GET', "./getcusid.php?id="+aid, true); http_request.send(null); if(s === false) { alert("not entered"); return false; } else { return true; } } function alertContents(http_request) { if (http_request.readyState == 4) { if (http_request.status == 200) { var tid = http_request.responseText; var res = confirm('Are you Sure you want to delete this customer?'); if(res && tid!=0) var res1 = confirm('The selected customer has a non-zero balance.Deleting this customer will cause an adjusting transaction to be created.Is this Ok?'); else return false; if (res1) return true; else return false; } else alert('There was a problem with the request.'); } } The getcusid.php page returns the value of tid;The above ajax code is returning true value if ok or cancel button is clicked. Please Help............ Link to comment https://forums.phpfreaks.com/topic/82626-solved-ajax-function-not-returning-proper-value/ Share on other sites More sharing options...
priti Posted December 28, 2007 Share Posted December 28, 2007 Hi I am having a customer list page.I have a delete button using anchor tag.If I want to delete a customer an alert should come and if the customer is having a pending invoice then one more alert should come.I have written this using ajax page by getting customer id. function Isconfirm(id) { var aid = id; var http_request = false; var s; if (window.XMLHttpRequest) // For Mozilla, Safari,... http_request = new XMLHttpRequest(); else if (window.ActiveXObject) // For IE { try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Giving up Cannot create an XMLHTTP instance)'); return false; } http_request.onreadystatechange = function() {s=alertContents(http_request); }; http_request.open('GET', "./getcusid.php?id="+aid, true); http_request.send(null); if(s === false) { alert("not entered"); return false; } else { return true; } } function alertContents(http_request) { if (http_request.readyState == 4) { if (http_request.status == 200) { var tid = http_request.responseText; var res = confirm('Are you Sure you want to delete this customer?'); if(res && tid!=0) var res1 = confirm('The selected customer has a non-zero balance.Deleting this customer will cause an adjusting transaction to be created.Is this Ok?'); else return false; if (res1) return true; else return false; } else alert('There was a problem with the request.'); } } The getcusid.php page returns the value of tid;The above ajax code is returning true value if ok or cancel button is clicked. Please Help............ Hello rekha, Its simple if your print variable before if(s==false) it will print 'undefined' . you have defined var s in the function but it is initialsed in other funtion either you make s global in this script or edit your script as follow http_request.onreadystatechange = function() {s=alertContents(http_request); if(s === false) { alert("not entered"); return false; } else { alert('return ture'); return true; } It work gr8 in both way hope you have good time ahead in coding regards Link to comment https://forums.phpfreaks.com/topic/82626-solved-ajax-function-not-returning-proper-value/#findComment-424543 Share on other sites More sharing options...
rekha Posted December 28, 2007 Author Share Posted December 28, 2007 Hi Thanks for your reply priti. I had tried the code suggested by you.But it is still giving undefined value.I want the function isconfirm(id) to return either true or false. Please help..... Link to comment https://forums.phpfreaks.com/topic/82626-solved-ajax-function-not-returning-proper-value/#findComment-424582 Share on other sites More sharing options...
priti Posted December 29, 2007 Share Posted December 29, 2007 Hello rekha, In start of script try to declare variable S make it global through out the javascript. regards, Link to comment https://forums.phpfreaks.com/topic/82626-solved-ajax-function-not-returning-proper-value/#findComment-425115 Share on other sites More sharing options...
rekha Posted January 3, 2008 Author Share Posted January 3, 2008 Hi priti I have solved the issue yesterday by using javascript window.location function. Thanks for your reply. Regards Rekha Link to comment https://forums.phpfreaks.com/topic/82626-solved-ajax-function-not-returning-proper-value/#findComment-429040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.