请问下面的这一段代码为什么不执行啊?是不是一定要先新建一个网站,然后才能够执行啊?谢谢!
<html>
<head>
</head>
<body>
<script type="text/javascript" language="javascript">
var xmlhttp = false;
function CreateXMLHttp(){
try{
xmlhttp = new XMLHttpRequest();
}
catch (e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (failed){
xmlhttp = false; //如果失败则保证 request 的值仍然为 false。
}
}
}
return xmlhttp;
}
xmlhttp = CreateXMLHttp();
xmlHttp.open("get","http://www.cnblogs.com",true);
xmlhttp.onReadyStateChange = getResult;
xmlhttp.send(null);
function getResult(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
alert(xmlhttp.responseText);
}
}
</script>
haha
</body>
</html>
<html>
<head>
</head>
<body>
<script type="text/javascript" language="javascript">
var xmlhttp = false;
function CreateXMLHttp(){
try{
xmlhttp = new XMLHttpRequest();
}
catch (e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (failed){
xmlhttp = false; //如果失败则保证 request 的值仍然为 false。
}
}
}
return xmlhttp;
}
xmlhttp = CreateXMLHttp();
xmlHttp.open("get","http://www.cnblogs.com",true);
xmlhttp.onReadyStateChange = getResult;
xmlhttp.send(null);
function getResult(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
alert(xmlhttp.responseText);
}
}
</script>
haha
</body>
</html>
xmlHttp.open("get","http://www.cnblogs.com",true);改成xmlHttp.open("get","fileName.xxx",true);就可以了
httpwebrequest抓取内容
<head>
</head>
<body>
<script type="text/javascript" language="javascript">
var xmlhttp = false;
function CreateXMLHttp(){
try{
xmlhttp = new XMLHttpRequest();
}
catch (e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed){
xmlhttp = false;
}
}
}
return xmlhttp;
}
xmlhttp = CreateXMLHttp();
xmlHttp.open("get","test1.html",true);
xmlhttp.onReadyStateChange = getResult;
xmlhttp.send(null);
function getResult(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
alert(xmlhttp.responseText);
}
}
</script>
haha
</body>
</html>
下面是test1.html<html>
<head>
</head>
<body>
中国哈哈
</body>
</html>
<html>
<head>
</head>
<body>
<script type="text/javascript" language="javascript">
var xmlhttp = false;
function CreateXMLHttp(){
try{
xmlhttp = new XMLHttpRequest();
}
catch (e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed){
xmlhttp = false;
}
}
}
return xmlhttp;
}
function getResult(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status ==0 || xmlhttp.status == 200){
alert(xmlhttp.responseText);
}
}
}
function getAjax()
{
xmlhttp = CreateXMLHttp();
xmlhttp.open("get","test1.html",true);
xmlhttp.onReadyStateChange = getResult;
xmlhttp.send(null);
}
</script>
haha
<input type='button' value='click me' onclick='getAjax();' />
</body>
</html>
xmlHttp.open("get","test1.html",true);
xmlhttp.onReadyStateChange = getResult;
改成
xmlhttp.open("GET","test1.html",true);
xmlhttp.onreadystatechange = getResult;javascript 是大小写敏感的http://www.mybuffet.cn
我这里收藏了点ajax视频,去找下,有你需要的,。
if(xmlhttp.status ==0 || xmlhttp.status == 200){
在本机的时候 xmlhttp.status 是 =0 的
<html>
<head>
</head>
<body>
<script type="text/javascript" language="javascript">
var xmlhttp = false;
function CreateXMLHttp(){
try{
xmlhttp = new XMLHttpRequest();
}
catch (e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed){
xmlhttp = false;
}
}
}
return xmlhttp;
}
function getResult(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status ==0 || xmlhttp.status == 200){
alert(xmlhttp.responseText);
}
}
}
function getAjax()
{
xmlhttp = CreateXMLHttp();
xmlhttp.open("GET","test1.html",true);
xmlhttp.onreadystatechange = getResult;
xmlhttp.send(null);
}
</script>
haha
<input type='button' value='click me' onclick='getAjax();' />
</body>
</html>
<head>
</head>
<body>
<script type="text/javascript" language="javascript">
var xmlhttp = false;
function CreateXMLHttp(){
try{
xmlhttp = new XMLHttpRequest();
}
catch (e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed){
xmlhttp = false;
}
}
}
return xmlhttp;
}
xmlhttp = CreateXMLHttp(); xmlhttp.open("GET","test1.html",true);
xmlhttp.onreadystatechange = getResult;
xmlhttp.send(null);
function getResult(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
alert(xmlhttp.responseText);
}
}
</script>
haha
</body>
</html>
test1.html
<html> <head> </head> <body> 中国哈哈 </body> </html>
不信试试这个连接
http://www.mybuffet.cn/html/htmlpage1.htm
http://www.mybuffet.cn