"Pistol whipped his ass to sleep," a Facebook user wrote before deleting a post showing the officer face down on the sidewalk.

Fellow cops were furious when they learned of the posts.

"He was laying there lifeless and people were standing around taking pictures," police Sgt. Heath Boackle, president of the Fraternal Order of Police, told Al.com. "If the tables were turned, and that was a suspect lying there, they would be rioting."

Janard Cunningham, 34, is charged with attempted murder after he allegedly pistol-whipped a Birmingham, Ala., cop with the officer’s own gun Friday. (Birmingham Police Department)

Suspect Janard Cunningham was taken into custody Friday and charged with attempted murder in the attack.

The 34-year-old has a violent criminal history, including an assault conviction in 2006.

Boackle blamed a national climate of poor police-community relations for the officer's injuries.

The deaths of unarmed black men at the hands of police across the country — including Michael Brown in Ferguson, Mo., and Eric Garner in Staten Island — have sparked massive protests.

The backlash has made officers "hesitate" in dangerous situations for fear they'll lose their jobs.

"If the officer would have shot him, then he would have shot an 'unarmed man,'" Boackle told Al.com. "Instead, he took the gun from the officer. The officer had every right to shoot him. We're lucky we're not talking about him killing the officer."

Police haven't released the name of the wounded detective. He was treated at UAB Hospital and released, authorities said.