Hi i'm just begining with wordpress so any help would be appreciated. I trying to get this working but the response data is undefined because of the 400 error. I've tried everything. Here's my code.
function simokydesigns_translate_scripts() {
wp_enqueue_script('customjquery', get_template_directory_uri()
.'/js/customjquery.js', array('jquery'));
wp_localize_script( 'customjquery', 'ajaxurl', admin_url( 'admin-
ajax.php' ) );
}
add_action( 'wp_enqueue_scripts', 'simokydesigns_translate_scripts' );
function get_ajax_sidebar(){
get_sidebar();
}
add_action('wp_ajax_get_ajax_sidebar', 'get_ajax_sidebar');
add_action('wp_ajax_nopriv_get_ajax_sidebar', 'get_ajax_sidebar');
//js/customjquery.js
(function($) {
$.ajax({
type: 'POST', // use $_POST method to submit data
dataType: "html",
url: ajaxurl,
data: {
'action': 'get_ajax_sidebar',
},
success:function(data) {
alert('Got this from the server: ' + data);
//$( '#widget-top' ).html( data );
},
error: function (data) {
console.log('error' + data);
}
});
/*$( '#widget-top').append( "<?php echo get_sidebar();?>" );*/
})( jQuery );