问题描述
我在jQuery中使用.load()方法但是我意识到对我的服务器的请求应该使用ISO-8859-1 charset而不是UTF-8。问题是我找不到如何设置load方法来使用不同的编码。我读到.ajax方法有'content-type'设置来执行此操作,但是加载方法呢?当我需要更新来自某些div的数据而不刷新页面时,我发现加载非常有用。
I'm using the .load() method in jQuery but I've realized that the request to my server should use ISO-8859-1 charset and not UTF-8. The problem is that I can't find how to set load method to use a different encoding. I read that .ajax method has 'content-type' setting to do this, but what about load method? I find load very useful when I need to update data from some divs without refreshing the page.
任何帮助都将不胜感激,谢谢。
Any help would be appreciated, thanks.
推荐答案
使用允许您指定新的ajax调用的设置。
Using ajaxSetup
allows you to specify the settings for new ajax calls.
with beforeSend
你可以提供一个回调函数来修改XMLHttpRequest对象,然后再发送它。
with beforeSend
you can provide a callback function to modify the XMLHttpRequest object before it's going to be send. jQuery Reference
提供有关的文档overrideMimeType()
:
Borrowing code from this answer you could do:
$.ajaxSetup({
'beforeSend' : function(xhr) {
xhr.overrideMimeType('text/html; charset=ISO-8859-1');
},
});
这篇关于jQuery加载方法charset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!