.load() kills character encoding

后端 未结 3 468
自闭症患者
自闭症患者 2020-12-19 10:49

I\'m using the following code to load in content:



        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 11:27

    jQuery's load() method uses the browser's innerHTML implementation to load the html returned from the request into the current document. This means that the incoming html has to use the same text encoding as the current document. You can't insert UTF-8 characters into an ISO 8859-1 document.

    You need to fix this at the server, not in Javascript. The server-side code that is responding with your original Html (that contains your jQuery) needs to include a content-type header with the right character encoding. If you're using Php, I think you've found an example of how to do that.

提交回复
热议问题