Looking around a little, it seems that you don't always need to apply for a Chinese visa in your home country, but you generally need to have at least a work permit in the country where you apply.
For example, the Chinese Visa Application Service Center in New Delhi “is responsible for receiving visa applications for visit to mainland China from ordinary passport holders who are Indian citizens and citizens of other countries possessing Indian permanent residence or work permits”.
The site of the Chinese embassy in Switzerland mentions that “for non-Swiss passports, a residency card is required (or Swiss employer certificate, or Swiss school certificate, etc.)”.
This isn't a definitive answer — you'd need to contact a Chinese embassy to be sure — but there is a presumption that the answer will be no in general.
Looking at non-official sources, it seems that the answer is yes in certain countries (perhaps certain neighboring countries?).
For example, a certain travel agency website has fee schedules for non-residents in Kazakhstan and India but not in Georgia .
They also claim that a Kazakhstan citizen can apply for a Chinese transit visa in Australia , and that a Georgian can apply for a Chinese visa from Kazakhstan but applying in Georgia requires being a Georgian national or resident .
travel.stackexchange.com/users/277/Gilles 'SO- stop being evil'
Edward Hasbrouck, a travel writer, has a pair of posts about getting Chinese visas outside of China specifically in Hong Kong.
The information is a little dated, but might still be useful.
http://www.hasbrouck.org/blog/archives/001498.html http://hasbrouck.org/blog/archives/001598.html
travel.stackexchange.com/users/11/user27478
It probably depends on the country.
I know of people that have gotten Chinese Visa's in Vietnam and Thailand
so it's certainly possible, really the best thing to do is ask the embassy in question.
As a fallback go to Hong Kong instead, I've got several visa's from Hong Kong for China, you can usually get them in less than a day through a travel agent or about two days through the official office.
travel.stackexchange.com/users/462/dageshi
I found this site (China Embassy in Kazakhstan Republic, only Russian and Chinese); there it says that you can apply for the China transit visa in this Consulate in the Kazakhstan republic, but I still can't find official information about it (don't know Chinese).
travel.stackexchange.com/users/19/VMAtm
Update:
It is possible again in Kazakhstan.
Uzbekistan also still possible, but more difficult than before.
It's not possible to get a Chinese visa in Kazakhstan at the moment.
It is possible in Uzbekistan and Kyrygzstan.
More information available in Caravanistan site.
EDIT :
Note - author is affiliated with site.
travel.stackexchange.com/users/2138/Caravanistan
July 2013:
We successfully got our Chinese visas while in Mongolia (link is to our blog).
It took a bit of extra effort and supporting paperwork compared to applying from our home country (UK), but it was cheaper and the Chinese Embassy staff in Ulaanbaatar are very helpful
travel.stackexchange.com/users/8060/Andrew
For some countries you can only apply for a visa in your home country (Russia is such a country)  Is China also such a country? I was thinking of applying for a visa in the Republic of Georgia or possibly Kazakhstan. I'm already travelling outside my own country (Australia) now.
Is it possible to apply for a Chinese visa while travelling outside your home country?
travel.stackexchange.com
<visas><china>
travel.stackexchange.com/questions/1043
travel.stackexchange.com/users/140/hippietrail
It is not always necessary to apply in your home country, but you will generally need to have at least a work permit in the country where you apply. It is possible in Uzbekistan and Kyrygzstan, but currently not in Kazakhstan. The travel writer Edward Hasbrouck has a couple of posts about getting Chinese visas in Hong Kong. At the moment it is not possibile to get a Chinese visa in Kazakhstan. However, It is possibile to get a  Chinese Visa outside of your country but it depends on the country. For example in countries like Uzbekisstan and Kyrygzstan this is a possibility but you most probably need a work permit in the country you are planning to apply for your visa in. For more information on this subject you can check out Edward Hasbrouck's  posts on getting a Chinese visa outside of China (especially in Hong Kong).
It is possibile to get a  Chinese Visa outside of your country but it depends on the country. For example countries like Uzbekisstan and Kyrygzstan this is a possibility but you most probably need a work permit in the country you are planning to apply for your visa in. Formore information on this subject you can check out Edward Hasbrouck's  posts on getting a Chinese visa outside of China (especially in Hong Kong.  At the moment it is not possibile to get a Chinese visa in Kazakhstan. 