欢迎访问 生活随笔!

凯发ag旗舰厅登录网址下载

当前位置: 凯发ag旗舰厅登录网址下载 > 编程语言 > c# >内容正文

c#

jqury ajax与c#后台交换数据 -凯发ag旗舰厅登录网址下载

发布时间:2023/10/11 c# 201 如意码农
凯发ag旗舰厅登录网址下载 收集整理的这篇文章主要介绍了 jqury ajax与c#后台交换数据 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

-------------------------------------------jqury ajax调用后台方法-------------------------------------------

js:
  function carstate(carid) {
            $.ajax({
                type: "post",
                url: "showmap.aspx/getcarstate",
                //方法传参的写法一定要对,str为形参的名字  
                data: "{'carid':'" carid "' }",
                contenttype: "application/json; charset=utf-8",
                datatype: "json",
                success: function (data) {
                    //返回的数据用data.d获取内容   
                    alert(data.d);
                }
            });
        }
后台:

using system.web.script.services;
using system.web.services;

[webmethod]
   public static string getcarstate(string carid)
   {
            return "hello world!";
    }

-------------------------------------------jquery ajax提交表单-------------------------------------------

html:


               
              
                   

                       
                   

               

               

                 
                   

                       
                   

               
     
               

                   

                       

          
                   


               
         
           

js:


 
 

c#后台(.aspx.cs文件)

protected void page_load(object sender, eventargs e)
        {

if (ispost)
                loginuser();
        }
        private void loginuser()
        {
            if (islocalrequest && !isrepeatpost)
            {
                string loginname = getformstring("t_name");
                string loginpwd = getformstring("t_pwd");
          
                if (loginname == "")
                    responsetext(newtonsoft.json.jsonconvert.serializeobject(new { res = 0, msg = "请输入用户名!" }));
                else if (loginpwd == "")
                    responsetext(newtonsoft.json.jsonconvert.serializeobject(new { res = 0, msg = "请输入密码!" }));
                   
                else
                {
                    string str = common.utils.md5(loginpwd.tolower());
                    t_member model = memberdal.m_memberdal.getmodel(string.format(" mb_name = '{0}' and mb_pwd='{1}'", loginname, common.utils.md5(loginpwd.tolower())));
                    if (model != null)
                    {
                        if (model.mb_islock == 1)
                            responsetext(newtonsoft.json.jsonconvert.serializeobject(new { res = 0, msg = "无法登录,该账户被锁定!" }));
                        else
                        {
                            model.mb_logintime = datetime.now.tostring();
                            model.mb_loginip = request.userhostaddress;
                            memberdal.m_memberdal.update(model);
                            response.cookies[":member"].value = common.serialize.serializeobject(model);
                            response.cookies[":member"].expires.adddays(1);
                            responsetext(newtonsoft.json.jsonconvert.serializeobject(new { res = 1, msg = "登录验证通过", data = "/master.aspx" }));
                        }
                    }
                    else {
                        responsetext(newtonsoft.json.jsonconvert.serializeobject(new { res = 0, msg = "账号或密码不正确!" }));
                    
                    }
                }
            }
        }

总结

以上是凯发ag旗舰厅登录网址下载为你收集整理的jqury ajax与c#后台交换数据的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。

  • 上一篇:
  • 下一篇:
网站地图