2013-10-30 11 views
8

içerik türü metin/html, text/plain değilken karakter kümesinin nasıl ayarlanacağını anlamakta güçlük çekiyorum veya text/xml, bunun yerine application/x-www-form-urlencoded içerik türü.ajax, setRequestHeader(), Content-Type, application/x-www-biçimli-urlencoded ve charset

Verilen bu (basitleştirilmiş) javascript kodu:

var xhr = new XMLHttpRequest(); 

Ben

xhr.open('POST', 'serv.php', true); 
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 

firebug içerik türü "olduğunu söylüyor, değil açıkça kodlamasını ayarlamak yapmak Eğer application/x -www-form-urlencoded; charset = UTF-8. "

Ben mesela ISO-8859-1 için charset ayarlarsanız, hala söylüyor

xhr.open('POST', 'serv.php', true); 
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1'); 

firebug "application/x-www-form-urlencoded; charset = UTF-8. " Ben

xhr.setRequestHeader('Content-Type', 'text/plain; charset=ISO-8859-1'); 

gibi bir şey denerseniz

o zaman charset saygı gösterir.

Her durumda

send() yöntemi şöyledir:

xhr.send('id=9&name=Yoda'); 

Neden Content-Type x-www-form-urlencoded olup olmadığını belirlemek charset dikkate almaz?

NOT: ISO-8859-1'i örnek olarak kullanıyorum. Amacım neler olup bittiğini anlamak.

cevap

11

Mime tipi application/x-www-form-urlencoded Mime türü parametreleri desteklemez (charset gibi). HTML5 özelliklerinin this section'una bakarsanız, karakter kümesinin nasıl belirlendiğini göreceksiniz (karmaşıktır). Özellikle, bölümün alt kısmında, karakter kümesinin mime türüne bir parametre olarak nasıl belirtilemeyeceğini belirten bir not bulunmaktadır.