weixin_33713707 2015-02-07 23:40 采纳率: 0%
浏览 18

Ajax调用Web服务

I'm trying to make a call using ajax to the web service to verify if a userame and password are correct. I am just returning pass or fail in xml. In my asmx page, I am getting an error "an object is required for the non static field , method, or property 'system.web.ui.page.request.get" Also, my xmlhttp.open URL, Am I doing it right ? Does anybody has a suggestion on how to solve this? This is my first post, please let me know if I have asked the question wrong or provided insufficient information. Thank you.

[WebMethod]
    public static string Auth() {
        String strConnString = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
        string str = null;
        SqlCommand com;
        string query = String.Format("select COUNT(TeacherID) from USERS where User= '{0}' and Password='{1}'", Page.Request.QueryString["username"], Page.Request.QueryString["password"]);
        object obj = null;
        SqlConnection con = new SqlConnection(strConnString);
        con.Open();
        com = new SqlCommand(query, con);
        obj = com.ExecuteScalar();
        con.Close();
        Page.Response.Write(obj);
    }



 function getResult() {

        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("lblMessage").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", "authenticate.asmx.cs?username=" + document.getElementById("txtUserName").value + "&password=" + document.getElementById("txtPassword").value, true);
        xmlhttp.send();

    }
  • 写回答

1条回答 默认 最新

  • weixin_33682790 2015-02-08 00:28
    关注

    "an object is required for the non static field , method, or property 'system.web.ui.page.request.get"-- this was the actual problem for the webservice. Solved with putting the following code

    HttpContext.Current.Request.QueryString["username"],   
    
    HttpContext.Current.Request.QueryString["password"]);
    

    instead of the above posted lines by the user which missed the prefixes.

    HttpContext.Current.
    

    The full code is the following:

    [WebMethod]
    public static string Auth() {
        String strConnString = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
        string str = null;
        SqlCommand com;
        string query = String.Format("select COUNT(TeacherID) from USERS where User= '{0}' and Password='{1}'",  HttpContext.Current.Request.QueryString["username"],  HttpContext.Current.Request.QueryString["password"]);
        object obj = null;
        SqlConnection con = new SqlConnection(strConnString);
        con.Open();
        com = new SqlCommand(query, con);
        obj = com.ExecuteScalar();
        con.Close();
        Page.Response.Write(obj);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料