Hi,
Generally speaking, the pronoun should relate to the closest previous noun of that type.
That would mean 1. James 2. the meat
In practice, it can be unclear. Sometimes in speech we need to ask a question to clarify it. 'Who is excited, John or James?'
Sometimes the context helps clarify it. 'The robber killed the man, so he will go to jail.'
If we want to be very clear, we can reword our sentences.
1) John is going to James's house for a party. John is very excited about the event.
2) A dog is eating meat, which is very dirty.
Best wishes, Clive