新手请教.get方法如何使用
刚学jquery,试了一个例子,有两个页面index.html,data.php,但每次执行都显示的都是乱码,请问该怎么办?
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<style type='text/css'>
ul{
border:1px solid black;
list-style:none;
margin:0pt;
padding:0pt;
float:left;
font-family:Vernada,arial,Helvetica,sans-serif;
font-size:12px;
width:300px;
}
li{
padding:10px 5px;
border-bottom:1px solid black;
}
</style>
</head>
<body>
<form>
<p>
Show list of:
<select id="choice">
<option value="">select</option>
<option value="good">Good Guye</option>
<option value="bad">Bad Guye</option>
</select>
</p>
<p id="result"></p>
</form>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#choice').change(function(){
if($(this).val()!='')
{
$.get(
'data.php',
{what:$(this).val()},
function(data){
$('#result').html(data);
});
}
});
});
</script>
</body>
</html>
data.php
<?
if($_GET['what']=='good')
{
$names=array('Sherlock Helmes','John Watson','Hercule Poirot','Jane Marple');
echo getHTML($names);
}
else if($_GET['what']=='bad')
{
$names=array('Professor Moriarty','Sebastian Moran','Charles Milverton','Von Bork','Count Sylvius');
echo getHTML($names);
}
function getHTML($names)
{
$strResult='<ul>';
for($i=0;$i<count($names);$i++)
{
$strResult.='<li>'.$names[$i].'</li>';
}
$strResult.='</ul>';
return $strResult;
}
?>
[解决办法]
没有配置php的环境