Generally the spelling with x is the Old Spanish (castellano antiguo) spelling. In the Old Spanish you'd have for example Don Quixote. This changed with establishment of The Real Academia Española, which published in 1754 published new edition of "Ortografia de la lengua castellana", which pretty much defined modern spelling. One of the changes was that the /x/ sound would be spelled with j instead of x, while x would only represent /ks/ sound.
However, México, being a proper name is exception from the rule. In fact México is the only spelling appearing in the official dictionary of Real Academia Española. Spelling Méjico is still sometimes used in Spain, but it's never used elsewhere in Spanish speaking countries.