2009-07-12 8 views
0

JavaScript를 처음 접했습니다. 프로토 타입을 시험 할 때 여기에 문제가 있습니다.Ajax.updater problem

로드 된 후 sample.jsp를 Ajax.updater로 업데이트하려고하지만 작동하지 않습니다. 여기 smaple.jsp의 소스.

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 

<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
     <script src="prototype.js"></script> 
     <script> 
      function f1(){ 
       var ajax = new Ajax.updater(
       {success: 'state'},'part.html' 
       ,{method:'get'}); 
      } 
      document.observe('dom:loaded', function() { 
       f1(); 
      }); 

     </script> 
    </head> 
    <body> 
     state: 
     <div id="state"></div> 
     <br> 
    </body> 
</html> 

아무도 내 코드에 문제가 있다고 말할 수 있습니까?

답변

1

시도 우선

또한 당신이 파이어 폭스와 불을 지르고 플러그인 작업을 시도하는 것이 좋습니다

은 "이 Ajax.Updater"(대문자 U)는, 내가 다른 시도 자바 스크립트

+0

@ Yonatan, "Updater"를 "Updater"로 변경 한 후에도 여전히 실패했습니다. 조언 해 주셔서 감사합니다. 방화 광을 설치했으며 자바 스크립트 코드 줄에 중단 점을 설정할 수 있지만 내 경우에는 디버그하는 방법을 모르겠습니다. 수행 방법을 알려주시겠습니까? – eric2323223

+1

@ eric2323223 : 방화 광 콘솔에 GET 요청이 표시됩니까? 라이브 http 헤더 플러그인 (https://addons.mozilla.org/en-US/firefox/addon/3829)을 사용하지 않을 수도 있습니다. 요청이 전송되는지 확인하십시오. (또는 서버를 디버깅하여 점검/로그 검사) –

+0

@Yonatan, 예, 방화범 입력기에서 GET 요청을 보았습니다. 다음에 무엇을해야합니까? – eric2323223

0

를 디버깅 할 수있는 좋은 방법입니다 하나는 작동

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 

<html> 
    <head> 
     <title>AJAX Zip Checker </title> 
     <link rel="stylesheet" href="style.css" type="text/css" /> 
     <script src="prototype.js"></script> 
     <script type="text/javascript" language="JavaScript"> 
      function checkZip() { 
       if($F('zip').length == 5) { 
        var url = 'checkzip.jsp'; 
        var params = 'zip=' + $F('zip'); 
        var ajax = new Ajax.Updater(
        {success: 'zipResult'}, 
        url, 
        {method: 'get', parameters: params, onFailure: reportError}); 
       } 
      } 
      function reportError(request) { 
       $F('zipResult') = "Error"; 
      } 
     </script> 
    </head> 
    <body> 

     <label for="zip">zip:</label> 
     <input type="text" name="zip" id="zip" onkeyup="checkZip();" /> 
     <div id="zipResult"></div><p/> 

    </body> 
</html> 

checkzip.jsp

<% 
     String zip = request.getParameter("zip"); 
     if (zip.equals("10009")) { 
%> 
new york 
<%} else {%> 
unknown 
<% }%> 

다른 사람들이 그 차이를 말해 줄 수 있습니까?