Generally, every foreigner wanting to visit the United States of America as a tourist, student or under some other temporary visa is allowed to apply for a non-immigrant visa. Applying for a non-immigrant visa cannot only be done at the U.S. Consulate or U.S. Embassy of one’s own home country.
Many foreigners apply in a third-country not knowing that this can or may not be favorable unless if you are travelling and have decided to enter the U.S.
However, there are instances in which you may not want to apply for a visa at a country not your own. Applying for a nonimmigrant visa at another country may not be what is best for you as the applicant especially if you have violated U.S. immigration laws.