I know it’s not possible to call an jQuery Plugin within an .ajax() loaded page, the only way is to write a function in the parent page and call this function in the function(data) part of the AJAX request. This works in general, but I’m stuck because my function needs a variable from the loaded content to work correctly and whatever I’m trying, I can’t get the variable from the loaded content into the parent function, see my example:
This is my function:
function doPaginate(maxpage) {
jQuery("#demo5").paginate({
count: maxpage
});
}
This is my jQuery.ajax() request:
function loadProfileTab(tab, ownerinfo) {
jQuery.post("./profile_ajax.php", {
task: 'profiletab',
v: tab,
user_id: ownerinfo
}, function(data) {
jQuery("#profile_content_wrapper").html(data);
doPaginate(maxpage);
});
}
What I’m trying is now to get the variable maxpage from the PHP loaded content into the function doPaginate(maxpage) within the AJAX request.
I know some workarounds, in example start a request first to get the result of $maxpage, then start a request again to use this result in the new request, but it seems to be not the “nicest” solution.
Can someone lead me to a better solution please? Or is it just impossible what I’m trying in my code example above?
Best regards!
You could add the value for the
maxpagevariable as a hidden field in the HTML returned by AJAX and use jQuery to find the value, something like this.Here’s the DEMO for this code.