I have a loop of posts and I allow a user to edit each post using ajax. When the edit button is clicked for the post I use ajax to retrieve the template part containing the edit form for the post. Easy enough to do by creating a function with 'get_template_part' and then localizing a script where I use $ajax to execute the function.
Now here is my problem. I need to process the form with ajax that is in the template part we've called. In order to do anything with jquery for that form, the jquery has to be added as an inline script to the template. So when the button is clicked inside the from to save and edits made, I then need to run my php function that processes any edits made. But I can't do that because I can't actually localize the inline script that will allow me to use that php function I've made. Any ideas.
UPDATE:
Ok so instead of adding the scripts to the template inline, I register the script inside the function that gets the template part and then print it which I thought would give me a chance to localize. The script works for the template part but it isn't localized.
add_action('wp_ajax_fetch_dashboard_edit_form', 'fetch_dashboard_edit_form');
function fetch_dashboard_edit_form() {
$post_id = $_POST['postId'];
$edit_type = $_POST['editType'];
include(locate_template('edit-'.$edit_type.'.php'));
wp_register_script(
'fod_edit_script',
get_bloginfo('stylesheet_directory') . '/libs/edit.js',
array( 'jquery' ),
null,
true
);
wp_localize_script(
'fod_edit_script',
'editAjax',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
)
);
wp_print_scripts("fod_edit_script");
}