bi kere sonuclar eşleşmiyor
if sonuc=="hata1" değil hata olacak
eğer çıktıyı direk alert etmek istiyorsan
function(sonuc){
alert(sonuc);

}