Camels spit in order to surprise, distract or generally ward off a threat. The “spit” from a camel is more than just saliva. It is mixed with the camel’s stomach contents as well.
Most people think of spraying saliva when they think of spitting. But saliva is a liquid, and it does not weigh very much. In order to fire the projectile further and have it do more, camels mix whatever is in their stomach with saliva. This is not something camel’s do often, and it is usually done only when camels are agitated. According to the San Diego Zoo site, camel spit is more like vomit than actual spit. Camels use it against predators to warn them off. Wolves are the main predators that camels must protect themselves from. It is possible to tell when a camel is about to spit by paying attention to its cheeks. Camel cheeks bulge and fill up right before they spit. The idea behind this behavior is to try to keep other animals or people away from them in order to avoid the need to fight them at all in the first place. Other animals engage in similar behavior. For example, cats hiss to try to keep animals away.