It depends on when they happen. If a person experiences them after exercise, doing warmup stretches may help. If spasms occur after spicy food or a large meal, dietary changes may prevent them.
Breathing exercises might also help calm diaphragm muscle spasms. If they are bothersome, a doctor may recommend antiseizure or other medications.