Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Get data to php with Ajax being called too many times.
Old 04-14-2010, 12:32 AM Get data to php with Ajax being called too many times.
Extreme Talker

Posts: 177
Trades: 0
I have a drop down, that onChange calls a http request and based on the result changes another drop downs attributes.

Here is the function that gets called when the drop down gets changed
Code:
function getTeeColors(courseid, gid)
{
    httpObject = getHTTPObject();
    if(httpObject != null)
    {
        httpObject.open("GET", "./golfIncludes/actions/~returnKnownCourseTeeColors.php?cid=" + courseid + "&gid=" + gid, true);
        httpObject.send(null);
        httpObject.onreadystatechange = enableTeeColors;
    }
    
}
Here is the function that the httpObject calls:
Code:
function enableTeeColors()
{
    if(httpObject.readyState == 4)
    {
        alert(httpObject.responseText);
    }
}
What the php page will output is tee colors (relating to golf), depending on which tee colors the user has enabled for a given course (which is the first drop down which triggers the http request)

My problem is:
Code:
 if(httpObject.readyState == 4)
    {
        alert(httpObject.responseText);
    }
Say I select a course (course1) that I have black and blue tees entered. When the javascript is done, it enables the teecolors drop down and enables the black and blue tees as selectable. Say course1 wasn't really what I wanted, and I really want course2. I'll change the drop down to course2, which only has blue tees entered for the course. When I change it to the correct course (course2) what ends up happening is the
Code:
alert(httpObject.responseText);
triggers twice. It triggers with "Black Blue" and then again with "Blue".

The "Black Blue" is a ghost of the first selection, which I don't want. Then the "Blue" gets alerted which is course2 which is really what I want. And as a result, instead of only the Blue tees being selectable, both the Black and Blue tees are selectable.

Any thoughts on why this is happening?

Thank you for any help.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Get data to php with Ajax being called too many times.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52454 seconds with 12 queries