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

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技术实现局部刷新商品数量和总价实例代码
完美解决ajax访问遇到session失效的问题
ajax内部值外部调用不了的原因及解决方法
以上就是ajax传递多个参数的实现代码的详细内容。
其它类似信息

推荐信息