Firstly, camels do not spit frequently, and only do so when provoked.
Second, they don't really "spit" since the substance they are spraying is not actually saliva!
Many animals have ways to tell others to stay away when they are defending their food or protecting themselves.
If they can convince an animal or person to keep its distance, then they may be able to avoid a fight.
This type of communication can be different for different kinds of animals. A bird may screech and dive at your head if it thinks you are too close to its nest. A dog may bark, and a cat may hiss.
A camel will bring some of its stomach contents into its mouth, mix them with saliva, and spit them at you.
That's a pretty clear signal to back off!
What a camel does is entirely different different to how a human spits.
Instead of emitting saliva, camels will emit some of the partially digested contents of one of the chambers of their fore-stomachs.
Similar to cows, camels are ruminants. When they get mad they will burp up some of their cud (the semi-digested contents of their fore-stomach).
Once this is in their mouth they flap their heads, and the cud slides out of their mouth onto their limp, droopy lips, which then fling the cud into the air.
In this way they can completely cover the upper half of a human!
The colour of their "spit" also depends on what they have recently eaten. Therefore, if the camel has been eating grass it will be greenish, and so on.