Are there any other symptoms?
If accompanied with a bloated gut I'd say it could be IBD - irritable bowel syndrome, which is managed with Prednisone.
Is your dog on medication? Liver and kidney enzyme tests might be required to rule out any issues with the medication having an adverse effect.
Foam usually signals an empty stomach - has the dog eaten recently?
The best thing to do would be to ship the poor fella off to a vet!