我正在使用Ajax,这是我第一次了解它。我有几个问题,如果有人愿意解释的话。我在为我的班级做点什么他给我们用的
<html>
<head>
<title>Ajax Examples</title>
<style type="text/css">
body {
font-family:      Trebuchet MS;
color:            #173F5F;
  background-color:#BFFFFF; 
 margin:10px;
 }
.formtable{
 border:2px solid #009999;
 background-color:#006B6b;
 color:#FF6600;
   }
.btnSubmit{
color:#FF6600;
background-color:#BFFFFF;
border:2px inset #FF6600; 
width:100px;
  }
h1{
color:#FF6600;
 }
input, textarea{
color:#FF6600;
border:1px solid #FF6600;
  }
hr{
background-color:#FF6600;
height:3px;
  }
#results{
color:#FF6600; 
width:300px;
 }
</style>
<script type="text/javascript">
function loadurl(dest) { 
try {
    // Moz supports XMLHttpRequest. IE uses ActiveX.  
    // browser detection is bad. object detection works for any browser 
     xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
     new ActiveXObject("Microsoft.XMLHTTP"); 
}
catch (e) { 
    //browser doesn't support
    alert("Get with the times man!"); 
}
 // the xmlhttp object triggers an event everytime the status changes 
 // triggered() function handles the events
 xmlhttp.onreadystatechange = triggered;
 // open takes in the HTTP method and url. 
 xmlhttp.open("GET", dest);
  // send the request. if this is a POST request we would have  
  // sent post variables: send("name=valerie&gender=female)  
  // Moz is fine with just send(); but   
  // IE expects a value here, hence we do send(null);
 xmlhttp.send(null);
  }
function triggered() {
 // if the readyState code is 4 (Completed)  
 // and http status is 200 (OK) we go ahead and get the responseText   
 // other readyState codes:  
 // 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
    // xmlhttp.responseText object contains the response. 
     document.getElementById("output").innerHTML = xmlhttp.responseText;
 }
 }
</script>
<title>LAB 14</title>
</head>
<body>
<h1>Simple Ajax</h1> 
<hr>
<p>This page will automatically load another file into page below.</p>
<a href="#" onClick="loadurl('info.html')" >click here to load another file</a>
<div id="output"></div>
</body>
</html>现在他所说的就是让我们把你的info.html页面做成你的个人主页--你可以把它做成简历或者其他你选择的东西。现在我有了一个我曾经做过的。我的问题是我有一个ftp服务器,我们应该把它上传到。我是否能够在上传之前看到页面,看看它是否工作,或者我做了什么或有什么不正确的页面上的错误。
发布于 2011-04-28 06:37:42
除非您在本地计算机上运行web服务器,否则这将不起作用。你看到这部分了吗?
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {这意味着,除非JavaScript从托管页面的服务器接收到"200 OK"状态代码,否则它永远不会处理if()块中的部分。
您可以尝试执行以下操作:
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200 || (xmlhttp.status == 0 && document.location.protocol == "file:"))) {不能保证这会起作用,但它应该会起作用。
https://stackoverflow.com/questions/5811384
复制相似问题