An infantry well-trained and prepared may be able to confound a cavalry charge: assuming they have the liberty in battlefield conditions, which is far from sure. Plenty of infantry formations have been ridden down by cavalry up until the 19th century.