<head>
<title>首页新闻测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="xmlhttprequest.js"></script>
</head>
<body>
<div id="News">新闻读取中……</div>
<script type="text/javascript">
var req = new XMLHttpRequest();
if( req )
{
req.onreadystatechange = function()
{
var News = "新闻读取失败";
try
{
if( req.readyState == 4 && ( req.status == 200 || req.status == 304 ) )
News = req.responseText;
}
catch(e)
{
News = e.description;
}
document.getElementById( ‘News‘ ).innerHTML = News;
};
req.open( ‘GET‘, ‘news.php‘ );
req.send( null );
}
</script>
</body>
</html>
<?php
echo iconv( "GB2312", "UTF-8", "这就是新闻" );
//echo "这就是新闻";
?>
如果注释掉第一句而开放第二句的话不仅看到的是乱码,在 IE 下还会出现 -1072896748 错误。有意思的是 IE 好像还会缓存由 XMLHTTPRequest 收到的内容,而 FireFox 则不会,所以在测试中会出现刷新 IE 很多次看到的还是旧数据的问题,可以在程序里加上下面 4 句话解决这个问题:
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=547782
http://iday./test/rss.htm
或者这里
http:///projects/iafw