Narrated Anas bin Malik:
The Prophet saw some sputum in the direction of the Qibla (on the wall of the mosque) and he disliked that and the sign of disgust was apparent from his face. So he got up and scraped it off with his hand and said, “Whenever anyone of you stands for the prayer, he is speaking in private to his Lord or his Lord is between him and his Qibla. So, none of you should spit in the direction of the Qibla but one can spit to the left or under his foot.” The Prophet then took the corner of his sheet and spat in it and folded it and said, “Or you can do like this. “
Read reference to this Hadith here.
If you don’t spit like this, good. If you do, do it the Sunnah way. If you see people doing it, educate them.
Also, whatever impurity you see in a mosque/place of prayer, clean it up!
The Prophet once spat in his clothes.
P.S. this ‘spit’ is a mixture of saliva and phlegm that’s uncontrollable. So being in a public place, it’s not decent to spit it on the road or a sidewalk. It’s better (according to the Sunnah) to spit it in a tissue/handkerchief/a corner of your cloth. Since they didn’t have tissues back then, Prophet (SAW) spit it out in his chadar.