나는 행과 열을 *로 채우는 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/>");
}
?>
아약스 코드입니까? –