Nel file ajax.php devi usare <?php come tag di apertura e non <? e basta.