Sayyiduna Anas bin Malik (may Allah be pleased with him) narrates that the Prophet (peace and blessings be upon him) saw phlegm on the qiblah wall, and this weighed heavily on him (peace and blessings be upon him), and signs of displeasure were evident on his face (peace and blessings be upon him). He (peace and blessings be upon him) stood up and scraped it off, then said: "When any one of you stands in prayer, he is speaking privately with his Lord," or he said: "His Lord is between him and the qiblah. So none of you should ever spit towards his qiblah; rather, let him spit to his left or under his foot." Then the Messenger of Allah (peace and blessings be upon him) took an edge of his garment or cloak, spat into it and rubbed it, and said: "Or let him do like this."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3595