我無法理解如何在 內容類型不是text/html,text/plain或text/xml,而是應用程序/ x-www-form-urlencoded內容類型。ajax,setRequestHeader(),Content-Type,application/x-www-form-urlencoded和charset
鑑於此(簡化)的javascript代碼:
var xhr = new XMLHttpRequest();
如果我不明確地設置編碼,
xhr.open('POST', 'serv.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
螢火告訴我,內容 類型是「應用程序/ x -www-form-urlencoded; charset = UTF-8。「
如果我設置的字符集爲ISO-8859-1例如,
xhr.open('POST', 'serv.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
螢火仍然告訴我:「應用程序/ x-WWW窗體-urlencoded;字符集= UTF-8。 「
如果我嘗試像
xhr.setRequestHeader('Content-Type', 'text/plain; charset=ISO-8859-1');
那麼尊重的字符集。
在所有的情況下,send()方法是這樣的:
xhr.send('id=9&name=Yoda');
爲什麼它不兌現如果Content-Type是X WWW的形式,進行了urlencoded我指定的字符集?
注意:我僅以ISO-8859-1爲例。我的目標是瞭解正在發生的事情。