I'd argue Afghanistan was an unclear and unfunded set of moving goal posts. There was an objective the US did succeed in; the death of the figurehead for the terrorist group that perpetrated September 11th 2001 attacks.
Forcing a regime change, society modernization (E.G. value women, everyone can vote, have a not-shit quality of life so there's something to stay at home and value), general reforms like that weren't something that was a clear goal for everyone involved. There was far too much corruption, in war profiteering among contractors, political institutions and figures, etc.
There was a great set of unfulfilled needs (IMO, offhand): a combination of engineers being free to do what _they_ think is necessary to build a stable and sustainable society, educators and a system of perpetuating that society in place once 'we' pull out, and politicians/diplomats to tackle and fix the social structure issues that aren't clearly objective and correctable with obvious actions, but more that require consensus and emotional support.
Oh, and a lot of funding in public, audited, bookkeeping that has verifiable results.
I'd really like to see the same domestically. The US GAO should produce reports for the average citizen, so they can understand where the funds going into the government come from (both per person, and broadly), and what value is derived from those funds.
It's really easy to say 'blow X up', 'end entitlement Y', 'shutdown Z'; but it's much more difficult to articulate preventative care, investment in the future, and improvement of the commons. Much like misinformation is easy and it's hard to spread the truth.
I think the failure to “win” on the part of the U.S. since 1945 has mostly come down to lack of political will. We could have done what McArthur wanted and dropped 50 atomic bombs on China and won the Korean War. Thankfully we didn’t. Our losses have not come from the inability of the U.S. military to obliterate (in a conventional way) our opponents.