JavaScript
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
/***update options***/
$.ajax({
type: \'POST\',
url: \'http://www.example.com/wp-admin/admin-ajax.php\',
data: {
action : \'hit-bottom\',
option : $option, // your option variable
new_value : $new_value // your new value variable
},
dataType: \'json\'
}).done(function( json ) {
alert( "Ajax call succeeded, let\'s see what the response was." );
if( json.success ) {
alert( "Function executed successfully and returned: " + json.message );
} else if( !json.success ) {
alert( "Function failed and returned: " + json.message );
}
}).fail(function() {
alert( "The Ajax call itself failed." );
}).always(function() {
alert( "This message is always displayed, whether the call failed or succeeded." );
});
}
});
functions.php
/* hit bottom of screen event */
add_action( \'wp_ajax_hit-bottom\', \'wpse_hit_bottom\' );
add_action( \'wp_ajax_nopriv_hit-bottom\', \'wpse_hit_bottom\' );
function wpse_hit_bottom() {
$option = $_POST[\'option\'];
$new_value = $_POST[\'new_value\'];
if( !isset( $option ) || $option == \'\' || !isset( $new_value ) || $new_value = \'\' ) {
die(
json_encode(
array(
\'success\' => false,
\'message\' => \'Missing required information.\'
)
)
);
}
update_option( $option, $new_value );
die(
json_encode(
array(
\'success\' => true,
\'message\' => \'Database updated successfully.\'
)
)
);
}