The Afghanistan war was very popular. OBL had coordinated the attacks on the World Trade Center and Pentagon. Almost every American citizen was out for blood. The Taliban was hosting him and weren't going to give him up easily. So we went through them to get him (even though we didn't).
The aftermath is where the popularity dwindled. Wars are easy, occupations are hard. And after dismantling the Afghanistan Taliban regime we thought we could be rebuild a better Afghanistan built on western standards. This was never going to happen.
Iraq was also popular. 80% of Republicans supported the incursion wholeheartedly. Slightly over 50% of Democrats supported the incursion, if WMDs could be found. Once Americans realized WMDs weren't going to be found support for the war in Iraq dropped stupendously. But support for the occupation was relatively high (for a while) because most Americans realized you break something you have to fix it.
For most Americans, war is hugely popular. But just the 1-2 months of actually fighting. The decades long nation building is what generals try and talk politicians out of.