Ajax get

前端之家收集整理的这篇文章主要介绍了Ajax get前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

HTML内容

<!DOCTYPE html>
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<Meta name="keywords" content="">
<Meta name="description" content="">
<title>ok</title>
<body>
<form>
<p>show list of:
<select id='choice'>
<option value=" ">select</option>
<option value="good">good guys</option>
<option value="bad">bad guys</option>
</select>
</p>
<p id="result"></p>
</form>
<script src="./js/jquery.js"></script>
<script src="./js/co.js"></script>
</body>
</html>

js内容

$(document).ready(function()
{
$('#choice').change(function()
{
if($(this).val()!=' ')
{
alert($(this).val());
$.get('./PHP/login.PHP',{what:$(this).val()},
function(data)
{
$('#result').html(data);
});
}
});
});

PHP内容

<?PHP if($_GET['what']=='good') { $names=array('sherlock','yu'); echo getHTML($names); echo 'nihao'; echo "<script>alert('yao');</script>"; } function getHTML($names) { $strR='<ul>'; for($i=0;$i<count($names);$i++) { $strR.='<li>'.$names[$i].'</li>'; } $strR.='</ul>'; return $strR; } ?>

原文链接:https://www.f2er.com/ajax/164376.html

猜你在找的Ajax相关文章