1
我正在嘗試使用ajax調用Web服務來驗證用戶名和密碼是否正確。我只是在xml中返回通過或失敗。在我的asmx頁面中,我收到一個錯誤「一個對象是非靜態字段,方法或屬性'system.web.ui.page.request.get」所必需的。另外,我的xmlhttp.open URL,我在做對 ?有人有關於如何解決這個問題的建議嗎?這是我的第一篇文章,如果我提問或提供的信息不足,請告訴我。謝謝。Ajax調用webservice
[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();
}
,能得到任何結果,任何錯誤,請提供更多信息。 – 2015-02-07 23:47:20
如果我把這個方法放在我的aspx.cs頁面的頁面加載中,它工作,返回1或0,但是當我把它放在我的web服務中時,我得到了「一個對象是非靜態字段需要的,方法,或屬性'system.web.ui.page.request.get「,下劃線錯誤來自Page.Request。和page.Response – CompressedAir 2015-02-07 23:49:22
使用HttpContext.Current.Request.QueryString,看看它是否有幫助... – 2015-02-07 23:57:33