dynamically change content of div with php

If you were to localize admin-ajax.php then if you add these functions to functions.php:

    add_action( 'wp_ajax_nopriv_create_posts', 'my_create_posts' );
    add_action( 'wp_ajax_create_posts', 'my_create_posts' );

function my_create_posts(){
    if (is_string($_POST['a'])) {

  $name = $_POST['a'];
  //echo $name; and soo on...

}
}

The ‘action’ in the ajax call is needed for defining to which ajax call to pair your function, defined in add_action.

Other thing is I don’t understand what are you doing with a, because $name is not used anywhere.

And if you want to check is a is being passed why not use isset($_POST['a'])

You would need to change in localize script the ajax url to:

'ajax_url' => admin_url( 'admin-ajax.php' )