Sometimes it can be a reaction to shock or surprise and the brain goes into shutdown as it can't cope which leads to fainting.Sometimes it's to do with a low level of blood sugar or glucose levels in the body which causes weakness and fainting.
Everytime I've fainted it's because of my blood pressure, which can be effected by not eating well, or by me being pregnant (past not present), or by excercise. My brother's passed out if they missed a meal as they were hypoglycemic and their blood sugar would drop too low.