The Prophet, peace and blessings of Allah be upon him, said:
“When any one of you is praying, let him not spit in front of himself, for Allah is before him when he prays.” (Reported by al-Bukhaari in his Saheeh, no. 397).
This is incompatible with khushu and good manners before Allaah.
He also said:
“When any one of you stands up to pray, he should not spit in front of himself, because he is talking to Allah – may He be blessed and exalted – as long as he is in his prayer place; and he should not [spit] to his right, because there is an angel on his right. He should spit to his left, or beneath his feet, and bury it.” (Reported by al-Bukhaari, al-Fath, no. 416, 1/512).
He, peace be upon him, said:
“When one of you stands to pray, he is talking to his Lord, and his Lord is between him and the qiblah, so none of you should spit in the direction of his qiblah, but to his left or under his feet.” (Reported by al-Bukhaari, al-Fath al-Baari, no. 417, 1/513).
If the mosque is furnished with carpets and so on, as is the norm nowadays, if a person needs to spit, they can take out a handkerchief or whatever, spit into it, and put it away again.