We have an ASP MVC application that leverages partial-page AJAX updates. When a user-driven action occurs on one panel of our screen, we need to ensure our jsTree (in a separate panel) updates.
However, attempting to act within the success: portion of the AJAX call does not work - this occurs too early, and the jsTree is not yet ready to accept these commands. Executing the same commands later works just fine.
We've worked around the issue as follows: -Upon the AJAX success, store the desired callback method in a new Javascript class:
var EPCStateMembers =
{
_callbackMethod: "",
StoreCallback: function (callbackMethod)
{
EPCStateMembers._callbackMethod = callbackMethod;
},
UseCallback: function ()
{
if (EPCStateMembers._callbackMethod != "")
EPCStateMembers._callbackMethod();
EPCStateMembers._callbackMethod = "";
}
}
Within the AJAX success, we call EPCStateMembers.StoreCallback()
Then, once the jsTree is ready (indicated by its own event, reselect.jstree) - we invoke
EPCStateMembers.UseCallback();
Functionally, this solution works.
However, before we resign ourselves to temporary Javascript state storers as our goto solution...I'd like to ask the question - does a better pattern or practice exist for such situations?