wp_localize_script
results in your data being printed to the page before your script tag via PHP, whether it be in wp_head
or wp_footer
, depending on where you’ve set your script to be output. Calling wp_localize_script
from an AJAX handler won’t do anything, you’re returning data via JavaScript.
What you can do is put any data you want to return from your AJAX handler in a json object with wp_send_json
, including the new value you want to use in place of ajaxload.post_id
. You’ll then have access to that data in your success
function where you can update the value of ajaxload.post_id
.
EDIT-
In your AJAX handler:
$response = array(
'post_id' => $next_key,
'something_else' => 'some other data'
);
wp_send_json( $response );
In your JS:
$.ajax({
type: 'post',
data: {
action: 'ajax_load',
post_id: ajaxload.post_id
},
success:function( data ) {
var result = $.parseJSON( data );
ajaxload.post_id = result.post_id;
}
});