2014-12-03 3 views
-1

나는 행과 열을 *로 채우는 PHP를 사용하여 간단한 코드를 작성했습니다. 필자는 URL localhost/squareService.php를 입력하여 PHP 코드를 테스트 했습니까? rows = 3 & cols = 3ajax가 출력을 표시하지 않습니다.

그러나 사용자가 js 및 html을 사용하여 행과 열의 수를 입력하려고하면 아무 일도 일어나지 않습니다. 이 코드가 어디에서 실패했는지 찾을 수 없습니다.

참고 : php는 squareService라는 별도의 파일에 있습니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

    <html lang="en"> 
    <head> 
     <title>consume Square Service</title> 
     <script language ="javascript" type="text/javascript"> 

     var xmlhttp; 

     function drawSquare(){ 

      xmlhttp = new XMLHttpRequest(); 
      var rows= document.GetElementById("rows").value; 
      var cols= document.getElementById("cols").value; 
      var url ="squareService.php?rows=" + rows + "&cols=" + cols; 
      console.log(url); 

      } 



     </script> 

    </head> 
    <body> 
     <div id="results"></div> 
     Rows:<input type="text" id="rows"/> <br/> 
     Columns:<input type="text" id="cols"/> <br/> 
     <input type ="button" value="Draw Square" onclick="drawSquare()"/> 

    </body> 
    </html> 

<?php 
    $rows = $_REQUEST['rows']; 
    $cols= $_REQUEST['cols']; 

     for($i=0; $i<$cols; $i++) 
     { 
      for($x=0; $x<$rows; $x++) 
      { 
       print("*"); 
      } 
      print("<br/>"); 
     } 



    ?> 
+0

아약스 코드입니까? –

답변

1

단순 오타,

var rows= document.getElementById("rows").value; 

가 기억

var rows= document.GetElementById("rows").value; 

변경, 자바 스크립트는 대소 문자를 구분합니다.

Reference

0

바로 내가 오타의 원래 "에서 getElementById는"그것은

+1

여전히 'getElemetByID'는 'getElementById'여야합니다. – Pupil

1

수정 코드의이 섹션 "에서 getElementById"을 했어야했다 있었다 것을 깨달았다 응시 한 시간 후 게시 같이 항상

function drawSquare(){ 

      xmlhttp = new XMLHttpRequest(); 
      var rows= document.getElementById("rows").value; 
      var cols= document.getElementById("cols").value; 
      var url ="squareService.php?rows=" + rows + "&cols=" + cols; 
      console.log(url); 

      } 

JS은 대소 문자를 구분합니다. 그래서 GetElementByIdgetElementById과 다릅니다.

관련 문제