I want to pass a variable into a .load() function, not the URL, but the function that would happen afterwards.
As you can see below, i have an if/else statement. I want to pass a variable into that.
At the moment i have 2 variables which sit outside this $next and $prev, these are outside of the method. I have tried making them global but that doesn’t work. Ideally i want these to be variables as it is used a couple of times.
var $next = $('.nav.next');
var $prev = $('.nav.prev');
method.open = function(settings) {
var $link_url = settings.url + ' ' + settings.element;
$($modal_inner).load( $link_url, function(response, status, xhr ) {
if (status == 'error') {
var msg = 'Sorry but there was an error: ';
$( '#error' ).appendTo( '.modal_inner' );
$( '#error' ).html( msg + xhr.status + " " + xhr.statusText) ;
}
else {
// Get pagination URL's
var $pag_next = $(this).find('#post').attr('data-pag-next');
var $pag_prev = $(this).find('#post').attr('data-pag-prev');
// If URL's add URL and show
if( $pag_next != '') {
$( $next ).attr('href', $pag_next);
}
if( $pag_prev != '') {
$( $prev ).attr('href', $pag_prev);
}
}
});
};
You can use variables in your parent scope, either local variables from your parent function or arguments from your parent function. For example, if you passed in
nextandprevinto theopenmethod like this, then you could access them in theloadhandler function.