Both can be translated to "Thanks for your answer". Which one is correct, and if both are, when?
Both are correct, and they have practically the same meaning.
By themselves, pro and por have quite different meanings. Basically, pro means 'because of' and por means 'for'.
Pretty much all the meanings of English for can be expressed with por, with the exception of the meaning of because of: If you want to say "for that reason", you have to say "pro tiu kialo", not "por tiu kialo".
Zamenhof used both pro and por after danki, with no recognizable difference in meaning. Both prepositions can be justified after danki: Using pro makes sense, because in a sense what you are thanking for is the cause of your thanking. Using por makes sense despite the fact that por cannot mean 'because of', as por can mean something like 'in exchange for': You can say "Mi pagis por la biero" ('I payed for the beer'), and analogously you can say "Mi dankis por la biero".
So both options are equally good, and they mean the same. Which one you choose to use is just a question of personal taste.
"pro" indicates a cause or a reason for something.
"por" indicates something that is favored somehow.
Thanking for something usually means, that this something is your reason to be thankful, so it should be "pro".
You could argue, that by thanking in advance for something (like an answer), you are actually favoring this something, but to me this is a bit farfetched.
So my general recommendation: Danku pro io.
I personally prefer pro, but both are used and I couldn't tell you which version is more common.
PIV has example with both prepositions for danki:
mi dankis lin por la tuja plenumo de mia deziro ("I thanked him for immediately fulfilling my desire", used by Zamenhof)
danki al iu pro io ("to thank someone for something")
Still according to PIV, one meaning of por is:
la objekton de interŝanĝo (the object of an exchange):
pagi cent frankojn por sia palto (to pay 500 francs for one's coat)
Rim. 4 Tie ĉi oni devas klasi la Z-an uzadon de por post danki (this is where Zamenhof's use of por after danki should be categorized)
Pro simply means "because of". So dankon pro via respondo is literally "I thank you because of your answer" and dankon por via respondo is literally "I thank you in exchange of your answer."
So, basically, both are correct and have the same meaning in practice (the difference is very thin).
You can use both, as correctly explained in most other answers, there is however an important difference with verbs:
pro can only be used with nouns, you have to make a noun out of the verb or use ĉar if you want to thank for a certain action.
por can be used directly with the i-form of the verb.
Because of this, while pro has a meaning that seems to be more fitting for this construction, por can actually be slightly more popular for explaining why you are grateful with a verb.
I really like the general explanation of the difference between por and pro, given here (I'm sorry I can't cite the person's name, besides just Andy).
As he says, the most overlap between the two words is in exactly the case you mention. Here is what the blog post says about that:
But the most overlap is here:
- vi dankos min por tio = you will thank me for that
- vi dankos min pro tio = you will thank me for that
The reason they can be both used to mean about the same thing, is because “pro” is saying “thanks on account of that” i.e. showing motive for the thanks. Whereas “por” is used in the sense of paying thanks for that (and we know that “por” can be used in paying expressions). I kinda prefer “pro”
So according to that, in this case the difference is very small. Both are considered correct.
I know it's only a dictionary, but JC Wells in his Esperanto Dictionary defines the two words as
por prepn for; por iri (in order to) go; por ke so that
pro prepn for, because of, owing to; (in exchange) for; prefix -peti intercede
From that I would conclude that pro would be the correct usage here, as you thank because of your response.
I recommend that you use por or pri. This is why:
Mi ne dankis lin por la donaco pro la indigno de mia edzino.
Firstly, the ostensible reason may differ from the real reason.
Secondly, simply adding ne creates an ambiguity: are you giving the reason you didn't thank, or the reason you might have been expected to thank?