实例 jQuery 发出 AJAX 请求,并随请求发送数据

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("input").keyup(function(){
    txt = $("input").val();
    $("span").load("/example/html/html_form.aspx", {suggest: txt});
  });
});
</script>
</head>
<body>
<p>Start typing a name in the input field below:</p>
First name:
<input type="text">
<p>Suggestions: <span></span></p>
<p>The file used in this example (<a href="demo_ajax_gethint.txt" target="_blank">demo_ajax_gethint</a>) is explained in our Ajax tutorial</p>
</body>
</html>
                    

输出结果