Я написал код с некоторыми изменениями. Надеюсь, он работает для вас
add_action( 'wp_enqueue_scripts', 'twentyseventeen_child_scripts' );
//Function to load js an localize vars
function twentyseventeen_child_scripts() {
wp_enqueue_script( 'inputtitle_submit', get_stylesheet_directory_uri().'/js/inputtitle_submit.js', array( 'jquery' ), '1.0', true );
$data = array(
'ajaxurl'=> admin_url( 'admin-ajax.php')
);
wp_localize_script( 'inputtitle_submit', 'PT_Ajax', $data );
}
add_action( 'wp_ajax_myajax_inputtitleSubmit_func', 'myajax_inputtitleSubmit_func');
add_action( 'wp_ajax_nopriv_myajax_inputtitleSubmit_func', 'myajax_inputtitleSubmit_func');
function myajax_inputtitleSubmit_func(){
$myArr = array(
'response' => 'xyz'
);
$myJSON = json_encode($myArr);
echo $myJSON;
die();
}
Past on External js файл
jQuery(document).ready(function($) {
jQuery(document).on('click', '#next', function(){
var title = jQuery('input[name=title]').val();
jQuery.ajax({
url: PT_Ajax.ajaxurl,
type: "POST",
data: {'action': 'myajax_inputtitleSubmit_func', title: title},
cache: false,
dataType: 'json',
beforeSend: function(){
},
complete: function(){
},
success: function (response) {
console.log(response);
}
});
});
});
Я протестировал этот код работает.