我用php编写了一个简单的代码,用*填充了行和列。我已经通过输入url localhost / squareService.php?rows = 3&cols = 3测试了php conde。
但是当我有用户尝试使用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/>");
}
?>
简单的错字,
改变
var rows= document.GetElementById("rows").value;
到
var rows= document.getElementById("rows").value;
请记住,JavaScript区分大小写。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句