jQuery加载方法charset [英] jQuery load method charset

查看:82
本文介绍了jQuery加载方法charset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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.

推荐答案

使用 ajaxSetup 允许您指定新的ajax调用的设置。

Using ajaxSetup allows you to specify the settings for new ajax calls.


使用任何函数的所有后续Ajax调用都将使用新的
设置,除非被单个调用覆盖,直到下一个
调用$ .ajaxSetup()。

All subsequent Ajax calls using any function will use the new settings, unless overridden by the individual calls, until the next invocation of $.ajaxSetup().

with beforeSend 你可以提供一个回调函数来修改XMLHttpRequest对象,然后再发送它。 jQuery Reference

with beforeSend you can provide a callback function to modify the XMLHttpRequest object before it's going to be send. jQuery Reference

Mozilla 提供有关的文档overrideMimeType()


覆盖MIME类型由服务器返回。对于
示例,这可以用来强制将流处理并解析为text / xml,如果服务器不报告它,则甚至是
。此方法必须被称为
在发送()之前。

Overrides the MIME type returned by the server. This may be used, for example, to force a stream to be treated and parsed as text/xml, even if the server does not report it as such.This method must be called before send().

你可以这样做的答案:

Borrowing code from this answer you could do:

$.ajaxSetup({
    'beforeSend' : function(xhr) {
        xhr.overrideMimeType('text/html; charset=ISO-8859-1');
    },
});

这篇关于jQuery加载方法charset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆