Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > AJAX

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-09-2009, 11:52 AM
smstew smstew is offline
Registered User
 
Join Date: Oct 2009
Posts: 1
AJAX PHP two div content

I have two calls that work fine independently. When I implement them both on the same page I am getting a "document.getElementById(..) is null or not and object" error. I first call getStateProvince(str) then I call getDistributors(strd). For some reason the script is not passing my second pageElement call.


Here is the code.

function callAHAH(url, pageElement, callMessage) {
document.getElementById(pageElement).innerHTML = callMessage;
try {
req=new XMLHttpRequest(); /* e.g. Firefox */
} catch(e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
/*some versions IE */
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
/*some versions IE */
} catch (e) {
req = false;
}
}
}
req.onreadystatechange = function(){responseAHAH(pageElement);};
req.open("GET",url,true);
req.send(null);
}

function getStateProvince(str){

if (str==""){
alert("Please select a Country.");

} else {
var strurl="getstate.php";
strurl=strurl+"?id="+str;
strurl=strurl+"&sid="+Math.random();
callAHAH(strurl,'displaystateprovince','Please wait; finding your selection..');
}
}


function getDistributors(strd){
/*alert(str);*/

if (strd==""){
alert("Please select a State/Province");

} else {
var strdurl="getdistributors.php";
strdurl=strdurl+"?id="+strd;
strdurl=strdurl+"&sid="+Math.random();
callAHAH(strdurl,'displaydistributors','Please wait; finding your distributors..');
}

}


Thanks for all of you help.
Reply With Quote
  #2  
Old 10-15-2009, 01:05 AM
jmajews1 jmajews1 is offline
Registered User
 
Join Date: Oct 2009
Posts: 3
req variable is global

In the callAHAH function, the req variable has global scope because you are missing "var req" declaration within the function scope. Since it is global, the first function creates the req object and sets the onreadystate change and executes the AJAX call asynchronously. The second call also sets req which overrides the previous reference and causing your issue.

To fix just declare your req variable to be local scope.

function callAHAH(url, pageElement, callMessage) {
var req;
....
}
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Php and ajax sabinkumar AJAX 0 02-16-2009 05:38 AM
Load content in a div by clicking on another div. How? z1freeride AJAX 3 01-11-2008 01:41 AM
Changing page container div with ajax wtvamp AJAX 2 12-14-2007 04:10 PM
Using AJAX to fit content in specific area wallyworth AJAX 0 05-18-2007 01:31 PM
change content of DIV, new content to be a Script rpesq Web 1 06-25-2005 02:30 AM


All times are GMT -4. The time now is 10:19 PM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.