您好,欢迎访问一九零五行业门户网

怎样用ajax传递多个参数

这次给大家带来怎样用ajax传递多个参数,用ajax传递多个参数的注意事项有哪些,下面就是实战案例,一起来看一下。
本文实例为大家分享了ajax传递多个参数的具体代码,供大家参考,具体内容如下
<html > <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 {               $('#pinfo').text(用户名或密码错误);             }           }         })       })     })   </script> </head> <body> 用户名<input id="txtusername" type="text" /><br /> 密码<input id="txtpwd" type="text" /><br />   <input id="button1" type="button" value="登录" /><br />   <p id="pinfo"></p> </body> </html>
webservice1.asmx
using system; using system.collections.generic; using system.linq; using system.web; using system.web.services; namespace ajax11 {   /// <summary>   /// webservice1 的摘要说明   /// </summary>   [webservice(namespace = http://tempuri.org/)]   [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]   [system.componentmodel.toolboxitem(false)]   // 若要允许使用 asp.net ajax 从脚本中调用此 web 服务,请取消对下行的注释。   [system.web.script.services.scriptservice]   public class webservice1 : system.web.services.webservice   {     [webmethod]     public string helloworld()     {       return hello world;     }     [webmethod]     public string validateuser(string username)     {       if (username == onlifes)       {         return 用户名已被占用,请选择其他;       }       else       {         return 可以使用,请继续;       }     }     [webmethod]     public string getdate()     {       return datetime.now.tostring(yyyy-mm-dd hh:mm:ss);     }     [webmethod]     public string login(string username, string pwd)     {       if (username == admin && pwd == 888888)       {         return true;       }       else       { return false; }     }   } }
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
ajax+session失效后即刻跳转登录页面
ajax访问到session失效如何处理
以上就是怎样用ajax传递多个参数的详细内容。
其它类似信息

推荐信息