日期:2014-05-16 浏览次数:20706 次
<!DOCTYPE html> <html lang ="en"> <head> <title>AJAX</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css"> <!--@jQuery--> <script type="text/javascript" src="assets/jQuery/jQuery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button#jqb1").click(function(){ var un = $("input#username").val(); alert(un);//至此都能正常工作 $.post("AJAX", {username:un}, function(result){//I can't make $.get() work...and $.post() can't work, too... $("p#jqp1").html(result); }); }); </script> </head> <body> <form>//去掉form即可正常工作 <input type = "text" id = "username"/> <button id="jqb1" class="btn">check username</button> <br/> <p id = "jqp1"></p> </form> </body> </html>
$(document).ready(function(){ $("button#jqb1").click(function(){ var un = $("input#username").val(); alert(un);//至此都能正常工作 $.post("AJAX", {username:un}, function(result){//I can't make $.get() work...and $.post() can't work, too... $("p#jqp1").html(result); }); }); return false;//阻止非IE浏览器表单提交 });