Thanks for the reply

basically the server returns json like this:

{
[{'name':'item1', 'value':'item1_val'},
{'name':'item2','value':'item2_val'}....... }



Keep in mind that this code is a work-in-progress....
(you can probably just ignore all of the observer/notify stuff.  The
issue happens on the first request using IE 6 only, not firefox)

[begin code snippet]
/*
        OnDemandDropdown javascript
*/

//the controller for each dropdown
function OnDemandController(dropdown, includeBlank, loadOnClick,
ajaxUrl, parent, parentLookupName)
{
        var self = this;

        dropdown.controller = this;

        if(dropdown.style.width == "")
                dropdown.style.width = "250px";

        this.dropdown = dropdown;
        this.includeBlank = includeBlank;
        this.ajaxUrl = ajaxUrl;
        this.isLoading = false;
        this.loadOnClick = loadOnClick;
        this.loadOnClickComplete = false;
        this.observers = new Array();
        this.parent = parent;
        this.parentLookupName = parentLookupName;
        this.loadingBox = $(dropdown.id + "_loading");


        if(parent != null)
        {
                dropdown.disabled = true;
                parent.controller.observers[parent.controller.observers.length] 
=
this;
        }

        if(loadOnClick)
        {
                dropdown.onmousedown = partial(doLoad,this);
        }

        dropdown.onchange = partial(notifyObservers, this);

        this.onNotify = function(parentController)
                {
                        log(this.id, " was notified");

                        this.dropdown.disabled = 
(parentController.dropdown.value == "");
                        clearDropdown(this.dropdown);

                        //reset flag
                        this.loadOnClickComplete = false;

                        if(! this.loadOnClick)
                                doLoad(this);
                }
}

function showLoading(controller)
{

        //show loading image
        controller.loadingBox.style.visibility = "visible";

        //show our loading message
        clearDropdown(controller.dropdown);
        appendChildNodes(controller.dropdown, OPTION({selected:"true"},
"Loading..."));

        controller.dropdown.focus();
}

function hideLoading(controller)
{
        //show loading image
        controller.loadingBox.style.visibility = "hidden";

        //loading message is already gone
}

function doLoad(controller)
{
        //if we are loading (or already loaded) then don't do anything
        if(controller.isLoading || (controller.loadOnClick &&
controller.loadOnClickComplete))
        {
                log("already loading...skipping this request");
                return;
        }

        showLoading(controller);
        callLater(.5, partial(doRequest,controller));
}

function doRequest(controller)
{
        log("OnDemandDropDown - doing request...");
        controller.isLoading = true;

        var url = controller.ajaxUrl;
        //if we have a parent, append the id to our url
        if(controller.parent != null)
        {
                if(controller.parent.value != "")
                        url = controller.ajaxUrl + "&" + 
controller.parentLookupName + "=" +
controller.parent.value;
        }

        //send the request
        url += "&nocache=" + (new Date().getTime()); //this doesn't work
        log(url);
        var d = loadJSONDoc(url); //IE HANGS HERE, WINDOW FLICKERS
        d.addCallbacks(partial(doResponse, controller), partial(onError,
controller));
}

function doResponse(controller, result)
{
        log("Response came back successful");

        //hide loading graphic
        hideLoading(controller);

        controller.isLoading = false;
        if(controller.loadOnClick)
                controller.loadOnClickComplete = true;

        bindDropdown(controller.dropdown, result, controller.includeBlank);
}

function onError(controller, err)
{
        alert("error loading data: " + err);
        controller.isLoading = false;

        hideLoading(controller);
}

function notifyObservers(controller)
{
        log(controller.dropdown.id + " changed.  Notifying observers.");
        for(var i=0; i<controller.observers.length; i++)
        {
                log("notifying " + controller.observers[i].dropdown.id);
                controller.observers[i].onNotify(controller);
        }
}
[end code]

Sorry I cannot post the issue on a public website as I am on an
internal project.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to