文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Ajax缓存和编码问题的最终解决方案

Ajax缓存和编码问题的最终解决方案

时间:2010-08-30  来源:蔚蓝的大海

ajax缓存和编码问题不难解决,下面是解决方法。

编码问题

默认使用UTF-8,如果一旦发现对象找不到的情况,可能js中输入了中文,同时js的编码格式可能为gb2312,可用记事本打开js,另存为utf-8格式的文档。

通过XMLHttpRequest获取的数据,默认的字符编码是UTF-8,如果前端页面是GB2312或者其它编码,显示获取的数据就是乱码。通过XMLHTTPRequest,POST的数据也是UTF-8编码,如果后台是GB2312或者其他编码也会出现乱码。

Cache缓存问题

由于IE的缓存处理机制问题,每次通过XMLHttpRequest访问动态页面返回的总是首次访问的内容,解决方法有:

1. 客户端通过添加随机字符串解决。如:

var url = 'http://www.bothv.com/';
url += '?temp=' + new Date().getTime();
url += '?temp=' + Math.random();

2. 在HTTP headers禁止缓存。如:

HTTP:

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="expires" content="Thu, 01 Jan 1970 00:00:01 GMT" />
<meta http-equiv="expires" content="0" />

PHP:

header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

ASP:

Response.expires=0
Response.addHeader("pragma","no-cache")
Response.addHeader("Cache-Control","no-cache, must-revalidate")

JSP:

response.addHeader("Cache-Control", "no-cache");
response.addHeader("Expires", "Thu, 01 Jan 1970 00:00:01 GMT");

3. 在XMLHttpRequest发送请求之前加上:

XMLHttpRequest.setRequestHeader("If-Modified-Since","0");
XMLHttpRequest.send(null);
    高质量的.NET空间,完美支持1.0/2.0/3.5/MVC等

New 90W charger with 8 renewable DC plugs ZM-50 series 124*56*40 mmDVI24+5 Female DIP straight 180° with fishgig plug connector pin OEM adapter connectorMini 5P A/F SMT USB connector cellphone USB connector mini usb port adapterUSB LAN Network SERVER Print PRINTER NAS STORAGE BT NEWTraffic Light Shaped 4 Ports USB Hub16*BNC F and 4 RCA F to 25 pin Male HD VGA Video Audio Monitor CableCute 4 Ports White and Red USB Hub 6 in 1 multifunction USB Card ReaderUSB A/M to A/M connector with long life time extension line OEMUSB A/M long body wire solder four-piece connector RoHS compliant OEM adapter connector3.5 DC to AU cellphone charging adapter connector stable performance2.5 DC to 2.5 adapter with long life time connector OEM standardized sizeWooden Bamboo Shaped 4Gb USB 2.0 Flash Memory DriveOpera Face Shaped USB 2.0 Flash Memory DriveD link 7DBI antenna wireless lan card WLAN card external WPS button DSSS spread spectrumTF USB Card Reader2.5 DC to MICRO 5P adapter for LG cellphone connector stable performanceSamsung 10P straight head USB connector cellphone connector mobile connectorUltra-thin power supply 90W chager adapter with 8 renewable DC plugs 124*56*45 mmHDMI 19P/M wire solder All-in-one HDMI high definition data plug HDMI connectorPCI 2 port VT6410 IDE expansion card with 32bit PCI interface up to 133Mbps transfer rate PCI cardCute White Plane 8Gb USB 2.0 Flash Storage DriveDVI24+5 Male solder 180°plugboard plug connector pin OEM adapter connectorUSB 3.0 2.5" SATA Hard Disk Drive Enclosure/Case/CaddyMini 5P B/F sinking SMT USB connector cellphone connector mini usb port adapterNew 160W DC 12V to AC 220V power adapter 769-100W DGL-LED seriesUSB A Male to A Male Cable Clear BlueFLP Mini 10P Female sinking USB connector cellphone connector mobile connectorUSB DC 2.5/3.5 Power CableYello Dog Bone Shaped 4Gb USB 2.0 Flash Storage DrivePCI -Express to 2 serial port expansion card support plug and play MosChip / NetMOS chip PCI cardBlock Shaped 4Gb USB 2.0 Flash Storage DriveLeather Button 2Gb USB 2.0 Flash Storage DriveHDMI-07(three-row) HDMI 19P/F HDMI high definition data plug HDMI connectorSilver and Black Vertical Type 4 Ports 7 Ports USB 2.O Hub for PC LaptopsSamsung 14P Male wire solder USB connector cellphone connector mobile connectorUSB 54M wireless lan card built-in smart chip antenna widely coverage area3.0 SATA adapter high speed fashion design transmission cardBeige White IEEE 1394 Firewire Cable, IEEE 1394 Firewire 4Pin Male to Male90W chager adapter with 8 renewable DC plugs SONY series 124*56*38 mmSamsung 10P Female SMT USB connector cellphone connector mobile connectorSamsung 10P (half is covered by iron) straight head USB connector cellphone mobile connectorUSB 2.0 Data Charger Adapter Retractable Cable for LG PhoneIPOD 30P welding on board(L=23.0mm) connector cellphone connector usb adapter mobile phone connector150W car DC 12V to AC 220V car power inverter USB adapter 763 LPD-150 seriesMini 16P Male wire solder USB connector mini usb port cell phone connector adapter3.5 DC Stereo Female Plug to 2*RCA Male Audio Output CableHDMI 19P/M wire solder typeC HDMI high definition data plug HDMI connectorStylish Wrist Chain Shaped USB 2.0 Flash Storage DriveSUPER VGA Male to Male MONITOR/LCD/PROJECTOR CABLE White
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载