event for partial view unload
-
we're loading all partials views to a common div.
$(divname).load(url);
on clicking a row in a table or clicking on an icon,or clicking on link, view changes. my requirement is, in a partial view, we have two text boxes which are free type. before this view clears, i need to save these data to db. what appropriate event is to be used before this view goes? i tried
$(document).unload
$(document).unbind
$(div).change
$(div).unloadetc. nothing worked. please help me to resolve this issue
-
we're loading all partials views to a common div.
$(divname).load(url);
on clicking a row in a table or clicking on an icon,or clicking on link, view changes. my requirement is, in a partial view, we have two text boxes which are free type. before this view clears, i need to save these data to db. what appropriate event is to be used before this view goes? i tried
$(document).unload
$(document).unbind
$(div).change
$(div).unloadetc. nothing worked. please help me to resolve this issue
Write a little intermediary function and call your div updates using it
var loadPartial = function(target, url, asyncPromise){
if(asyncPromise){
asyncPromise().done(function(){target.load(url)});
}else{
target.load(url);
}
}You can then update your values via AJAX safely before the div is loaded, or not pass a callback if that's not appropriate for a particular navigation. Using $(button).click for the save of ease, I don't know what your navigation event looks like.
$(button).click(function(){
loadPartial($(div),this.url,$.ajax({.../*update your database*/}));
});It's not the prettiest thing, but it's flexible.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli