- If combat hasn't started, your PC can't ready an action. Actions can't be readied when not in combat; this is discussed at length in the Dungeon Master's Guide (25–6).
- If the DM said, "Roll initiative," your PC can, on your PC's turn, ready an action. However, readying an action doesn't give your PC any senses that your PC doesn't already possess. Unlike, for example, the trigger of the spell contingency, your PC's readied action can't be triggered by a stimulus your PC isn't aware of.
In this case, your PC's readied action would trigger, but it would trigger only after the attack roll determined if the invisible foe's attack hit and dealt damage or missed. The ready action I attack the creature is fine, but the trigger When I'm attacked tries to interrupt a process that resists interruption. That is, your PC can't take an action that's predicated upon the foe finishing its action before the foe finishes its action.
Unlike movement or casting a spell, making an attack roll is a one-step process, occurring all at once. The Player's Handbook on Attack Roll says
An attack roll represents your attempt to strike your opponent on your turn in a round. When you make an attack roll, you roll a d20 and add your attack bonus. (Other modifiers may also apply to this roll.) If your result equals or beats the target’s Armor Class, you hit and deal damage. (134)
A creature that's affected by an effect like the typical invisibility spell does not give the defender a window in which to take actions in the quantum time between the creature becoming visible because it made an attack roll and the result of the creature's attack roll still being unknown. The creature's invisible while it's making that attack, it makes that attack by making an attack roll, and that attack roll's result determines if the attack hits and deals damage or misses. (Were this not the case, folks wouldn't suffer any penalties for being attacked by invisible attackers—if a typical invisible creature became visible upon, for instance, making the attack roll but before the attack roll's outcome is determined, the attacker would be visible when the outcome is determined, negating the advantage invisibility typically provides!)
So, yeah, as the defender in this situation, your PC is going to have to learn the result of the invisible attacker's attack roll the hard way—when the attacker's invisibility effect ends because the attacker either dealt damage to your PC or the attacker's attack missed the PC. Only then will your PC's readied action's trigger will be pulled, and your PC can attack.
To be clear, as a benefit of your PC having readied rather than delayed, after the invisible foe's attack is resolved and the foe's visible, this DM would put your PC ahead of the formerly-invisible foe in the initiative order, resolve your PC's readied action, then finish the formerly-invisible attacker's turn. Had your PC simply delayed—your PC wanting to make a full attack if the invisible foe reveals itself, for instance—, then your PC would end up in the initiative order behind the foe. Whether this is small consolation or shifts the tide of battle depends mightily on the circumstances.