2011-04-27 3 views
0

저는 Ajax와 협력 중이며, 이것에 대해 처음 배우게됩니다. 누군가가 설명하기 좋다면 몇 가지 질문이 있습니다. 그가 우리에게 준 나는이 당신에 대해 당신의 info.html 페이지를 만들기 위해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> 

이제 그는 말했다 모두가 우리를 위해 인을 사용하는 내 클래스에 대한 뭔가를하고 있어요 - 당신은 이력서 또는 다른 것을 만들 수있는 당신의 선택. 이제 나는 그랬다. 내 질문은 우리가 그것을 업로드 할 가정하는 FTP 서버가있을 것입니다. 업로드하기 전에 페이지를보고 작동하는지 확인할 수 있습니까, 아니면 무언가를하고 있거나 잘못된 페이지가 있습니다.

+0

원인 파일을 위로 당길 때 링크를 클릭해도 입력 한 내용이 표시되지 않습니다. – norris1023

답변

0

로컬 컴퓨터에서 웹 서버를 실행하지 않는 한 작동하지 않습니다. 이 부분 보이니? 자바 스크립트 페이지를 호스팅하는 서버로부터 "200 OK" 상태 코드를 수신하지 않으면, 그 사상 if() 블록 내부의 부품을 처리하지 않음을 의미

if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { 

.

if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200 || (xmlhttp.status == 0 && document.location.protocol == "file:"))) { 

이 작동한다는 보장을하지만 수행해야합니다

대신이 시도 할 수 없습니다.

+0

알았어. 나는 그것을 필로어에 업로드하면 그것을 볼 수 있어야한다는 것을 이해한다. 나는 내 학교 ftp에 로그인하는 데 문제가있다. – norris1023

0

코드를 편집하는 대신 간단한 웹 서버를 설치하여 코드를 테스트하는 것이 가장 쉽습니다.

매우 단순한 바보 같은 경우 Windows를 사용하는 경우 AnalogX의 을 권하고 싶습니다. 정말 경량이며 필요한 것을 수행합니다.