AJAX wp-mysql running too slow

When you call the database directly rather then using the $wpdb object its faster for a simple reason which is you only call the database, and the when you use $wpdb it loads extra functions and basically most of WordPress before you can use the $wpdb object.

What you should try is to use the WordPress Ajax api (not really an api but the right way to use ajax with WordPress). Basically you need to wrap your code in a function and make sure you die at the end:

function my_ajax_callback(){
    $getLetter = $_GET['letter'];
    global $wpdb;
    global $post;

    $result = $wpdb->get_results('SELECT * FROM wp_posts where post_title LIKE "'.$getLetter.'%" AND post_status = "publish" AND post_type="post"');
    while($row = $result)
    {
      echo '<a href="' . $row["guid"] . '">' . $row['post_title'] . '</a><br>';
    }
    die();
}

then you need add an action hook:

//if you want only logged in users to access this function use this hook
add_action('wp_ajax_ACTION_NAME', 'my_AJAX_processing_function');

//if you want none logged in users to access this function use this hook
add_action('wp_ajax_nopriv_ACTION_NAME', 'my_AJAX_processing_function');

*if you want logged in users and guests to access your function by ajax the add both hooks. *ACTION_NAME must match the action value in your ajax POST.

then just direct the ajax call to admin-ajax.php and add the ACTION_NAME:

<script type="text/javascript">
jQuery(function($) {
    $(document).ready(function() {
    $("#Loading").hide();
        $(".letter").bind('click', function(){
            $("#Loading").fadeIn(); //show when submitting
            var val = $(".letter").val;
            var data = {action: 'ACTION_NAME', letter: val};
            $.ajax({
                 url:'url to wp-admin/admin-ajax.php',
                 success:function(data){
                    $("#Loading").fadeOut('fast'); //hide when data's ready
                    $("#content1").html(data);
                 }
            });
        });
    });
});
</script>

this way it won’t load all of WordPress just for that ajax call.