Ajax如今在前端可谓是出尽风头,只要是前端项目几乎都有它的出现,本篇文章来看看实现多参数吧。
例1:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="js/Jquery1.7.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('#Button1').click(function () { var username = $('#txtUserName').val(); var pwd = $('#txtPwd').val(); $.ajax({ type: "post", contentType: "application/json", url: "WebService1.asmx/Login", data: "{username:'" + username + "',pwd:'" + pwd + "'}", success: function (bukeyi) { if (bukeyi.d == 'true') { window.location = 'HTMLPage1.htm'; } else { $('#divinfo').text("用户名或密码错误"); } } }) }) }) </script> </head> <body> 用户名<input id="txtUserName" type="text" /><br /> 密码<input id="txtPwd" type="text" /><br /> <input id="Button1" type="button" value="登录" /><br /> <div id="divinfo"></div> </body> </html>
例2:
$.ajax( { url: "${pageContext.request.contextPath}/user/login" , async: false , type: "post" , data: { 'userName': userName , 'password': password } , dataType: "json" , success: function (data) { flag = data.checkResult; if (flag == true) { location.href = "/user/homepage"; } else { location.href = "/user/toLogin" } } });
以上就是本篇文章的所有内容,对于ajax传参小伙伴们记住了吗?还需要了解更多java项目中常见问题请记得关注我们了解详情。
推荐阅读: