Most people who end up in the ER after taking 'ecstasy' are suffering from drug induced anxiety/bad psychological reactions. Those people usually aren't in medical danger.
Among the people who do have a medically serious (even fatal) problem, most cases seem to involve severe overheating, which can be due to overdoses, fake/adulterated pills (PMA is particularly dangerous), or in some cases drug interactions (with either other recreational drugs or prescription medications.)
Other somewhat common causes of ER visits include hyponatremia (drinking too much water, which can be fatal), heartbeat irregularities and seizures.