The news that Senator John McCain has brain cancer appears — at least momentarily — to have unified sharply divided Republican and Democratic politicians in support of a man some praised on Wednesday night as an “American hero.”

Almost immediately after the news was announced, Mr. McCain’s colleagues, past and present, took to social media to wish him well. The praise poured in from politicians on both sides of the aisle who have served under various administrations over Mr. McCain’s decades-long career.

Well wishes came from senators who have been at odds for weeks amid a debate about heath care, former presidents and even one of Mr. McCain’s congressional colleagues who is himself recovering from surgery.

Representative Steve Scalise, who was critically injured last month during a mass shooting at a congressional baseball practice, tweeted his support for Mr. McCain.