Ajax call with javascript in post content (not enqueued)

If you add the script inline you don’t need to use wp_localize_script. All you have to do is directly print your inline script exactly as you need it dinamically.

For example, in your template:

<?php
   // The PHP code of the template here
?>
<script>
jQuery(document).ready(function($){
  var s=1;

  $('button').on('click',function() {
    //wfire the ajax call
   jQuery.ajax({
     url : postbutton.ajax_url,
     type : 'post',
     data : {
        //name of the function defined in the main plugin php file
        action : 'function',
        ajax_url : <?php echo esc_js( admin_url( 'admin-ajax.php' ) ); ?>;
     },
     success : function( response ) {
        alert(response);
     }); 
  });
});
</script>
<?php
    // PHP code of the rest of the template
?>

Anyway you are doing it wrong. If you print inline scripts directly, you can not use the power of WordPress dependencies manager and you can end up with lot of problems. For example, if you decide to move jQuery to the footer, your inline JavaScript, which depends on jQuery, will stop working. Another example is the imposibility of localize the script because it has not an associate handle.

So, if your script depends on another, ALWAYS use WordPress dependencies manager.

And you can enqueue the scripts only in single posts, that is not a problem:

add_action( 'wp_enqueue_scripts', 'function_enqueue_scripts' );
function function_enqueue_scripts() {
    if( is_singular( 'post' ) {
        // Enqueue my script that depends on jQuery
        // only in single post view
        wp_enqueue_script( 'my-script', get_template_directory_uri() . '/script.js', array('jquery'), '1.0', true );
    }
}

Since the upcoming WordPress 4.5 you can print inline scritps with dependencies using the new function wp_add_inline_script(). Until then, I repeat, never print scripts that depends on another or you can not manage the dependencies, including localization.