I have a fairly simple ajax action link. The purpose of the action link is to fetch a partial view from the server and replace the contents of a div with new content.
The code looks something like:
<%= Ajax.ActionLink("click me", "GetThing",
new { Mode = "Simple"},
new AjaxOptions {
UpdateTargetId = "thingDiv",
OnComplete = "completeGetThing"
})%>
As you can see, the action link just replaces the content of a div tag in the page (thingDiv) with new content from the server.
I also have a javascript function being called for the OnComplete event. The callback function here needs to do some things with the content that is loaded into thingDiv.
Here is a simplified example of what I'm doing in javascript:
function completeGetThing{
if($("#thingDiv #subThing").length > -1){
doOtherThing();
}
}
I'm just using jQuery to fetch an element called "subThing" from within the div that we are updating.
But what I've discovered is that the OnComplete function appears to fire off before the HTML in thingDiv is actually replaced... so when my callback goes to look for the "subThing" element, it doesn't find it.
This is a VERY simplistic example of what I'm doing.
I am looking for good recommendation for how I might go about solving this problem, or better yet somone to point out something I've overlooked that can get the job done.
Thanks!