Rashi says this on Bamidbar 21:1 (English translation here):
יושב הנגב. זה עמלק (שם) שנאמר (במדבר יג, כט) עמלק יושב בארץ הנגב ושנה את לשונו לדבר בלשון כנען כדי שיהיו ישראל מתפללים להקב"ה לתת כנענים בידם והם אינן כנענים ראו ישראל לבושיהם כלבושי עמלקים ולשונם לשון כנען אמרו נתפלל סתם שנאמר אם נתון תתן את העם הזה בידי (מדרש אגדה):
Basically, after Aharon died, a group of Amaleikim attacked the Jews. They spoke like Canaanites, hoping the Jews would pray that Hashem deliver the Canaanites into their hands; since they were Amaleikim, the prayer would fail. However, they didn’t disguise their clothing. Unsure of who this people actually was, the Jews prayed that Hashem deliver “this nation” - whoever it may be - into their hands, and they were successful.
The clear implication from Rashi is that had the Amaleikim successfully tricked the Jews into praying to be saved from the Canaanites, their prayer would indeed have failed, as they prayed for the wrong thing.