Double it up. Use a cheap line of infantry to distract and pin (large numbers of infantry, too, so that they don't die too quick), and then flank the phalanxes with your javelin armed infantry or heavier AP infantry. To only fight phalanxes with infantry is tough, though, and you should really invest in some AP or heavier infantry with the Hai.