按钮的type是submit的form 按enter键都是会自动提交的;但是涉及到跨域请求时,用到async,form表单的id=login
$(document).ready(function() { $('#login').submit(function() { var address = aa.php'; var username = $('#usernames').val(); var password = $('#passwords').val(); $.ajax({ async:false, type: "POST", url: address, data:"username="+username+"&password="+password, crossDomain:true,//跨域操作 dataType:'JSONP', jsonp:"jsonpcallback" }); return false; }) }) function jsonpcallback (msg){ if (msg['status'] == '1') { location.reload();//页面刷新 }else{ alert(msg['msg']); $('#thelogin').fadeIn("slow"); $('#logined').fadeOut("slow"); } }