Faced with political turmoil at the top, a slowing economy, and a young and wired population restless for change, China’s Communist rulers appear to have dusted off a time-tested tactic: blaming foreigners for the country’s problems.

This time, however, the technique does not seem to be working as well as it used to. Judging from a torrent of online criticism, it may even have backfired.

In mid-May — as blind legal rights activist Chen Guangcheng was garnering worldwide headlines for his escape from house arrest to the U.S. Embassy and his bid to travel to the United States — Beijing’s Public Security Bureau announced a 100-day crackdown on foreigners staying illegally in the city. Beijing is home to about 120,000 foreigners.

The campaign was announced just days after a May 8 incident, caught on video, in which an apparently inebriated British man attempted to assault a young Chinese woman and was then set upon and beaten by several Chinese men passing by.

Since then, official media and popular Chinese Web sites have been filled with accounts or depictions of similar incidents, most of which have drawn comments denouncing the foreigners’ bad behavior.

A May 14 video posted online, for example, showed the principal cellist with the Beijing Symphony Orchestra, a Russian, getting into a fight on a high-speed train from Shenyang to Beijing after he placed his bare feet atop the seat in front of him. When a female passenger complained, Oleg Vedernikov hurled an unprintable Chinese slur at her. He apologized several days later, speaking in Russian in a video also posted online. But it was too late to stop the orchestra from dismissing him.

Video of “suspected Koreans” assaulting Chinese women in a KFC restaurant in Chengdu also went viral, provoking general outrage.

But public opinion appeared to shift after an anchorman on government-owned CCTV International — the channel that promotes itself as presenting China’s face to the world — delivered a diatribe against foreigners on his Sina Weibo account, the local equivalent of Twitter.

“Cut off the foreign snake heads,” Yang Rui wrote May 16. “People who can’t find jobs in the U.S. and Europe come to China to grab our money, engage in human trafficking and spread deceitful lies to encourage emigration. Foreign spies seek out Chinese girls to mask their espionage and pretend to be tourists, while compiling maps and GPS data for Japan, Korea and the West.”

Yang capped his tirade against “foreign trash” with a salute to the Chinese government for its recent decision to expel Melissa Chan, a U.S. journalist at the news network al-Jazeera’s Beijing bureau. “We should shut up those who demonize China and send them packing,” he wrote.

The online response, far from being supportive, was withering, with many commenters calling the CCTV host an “idiot” and far worse epithets, most unfit to print. “You being a TV presenter is a waste of time,” one wrote. “You should join the Central Propaganda Department.”

Several others accused Yang, and the Communist Party, of trying to stir up a modern-day version of the Boxer Rebellion, the nationalist uprising against foreigners, unequal treaties and Christian proselytizing that began in 1898.

Many began to voice suspicion that the spate of stories about misbehaving foreigners was part of an effort by the government to deflect public attention from its problems. “Is there an anti-foreign campaign?” asked one Weibo poster using the name Elyaniu. “Is there an invisible hand manipulating public opinion?”

Yang later tried to soften his broadside, saying that by “foreign trash,” he meant people like the inebriated Briton or the Russian cellist, not the “silent majority” of law-abiding expats. He also quibbled with an initial translation of his characterization of Chan.

Despite his efforts to backtrack, the episode — and the criticism it generated — showed the apparent limits of foreign-bashing in China, where the urbanized “Weibo generation” is increasingly plugged in, informed and impervious to official or unofficial campaigns or pronouncements.

“In China, there’s a strange mentality, which is — we always need to create an imaginary enemy to feel safe,” said Li Chengpeng, an independent columnist. But, he added, “I know people around me, not only intellectuals and entrepreneurs, but ordinary people working in restaurants and communities. What they care about is not ‘foreign devils,’ but their real lives — sunshine, clean air, food and freedom.”

The Beijing Daily newspaper has discovered as much each time it has tried to stir up popular sentiment against U.S. Ambassador Gary Locke. After Chen, the blind activist, turned up at the U.S. Embassy, the Beijing Daily and other state-controlled newspapers in the capital launched a coordinated editorial attack on Locke, accusing him of, among other things, pretending to be an ordinary guy by flying economy class, staying in cheap hotels, carrying a backpack and paying for his Starbucks coffee with a coupon. All that, the Beijing Daily suggested, reflected an insidious American plot to curry favor with the masses.

The attack prompted so much derision that the paper shut down its comments section. Locke, with his Chinese roots and casual style, is popular here, and many Netizens noted that no Chinese leader would ever be seen flying economy class or carrying a backpack.

That didn’t stop the paper from demanding this week that Locke reveal his assets, presumably to prove his ordinariness. The U.S. Consulate in Shanghai then posted the publicly disclosed assets of both Locke and President Obama. The result: another backlash, with Netizens asking why U.S. officials made so little when even Chinese provincial party bosses are wealthy and never disclose their net worth.

China has also learned that a campaign against foreign lawbreakers can cut both ways. On May 17, the State Department warned that teachers in the 60-plus Chinese government-sponsored Confucius Institutes throughout the United States — schools set up to promote Chinese culture — will have to leave the country by June 30 if they lack proper credentials.

Researcher Liu Liu contributed to this report.