service .cs文件代码是:
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string UserLogin(string u_name,string user_pwd)
{
string result = "true";
if (u_name == "unicolumn" && user_pwd=="admin")
{
result = "true";
}
else
{
result = "false";
}
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(result);
}
我的ajax调用代码是这样的:
function apiLogin()
{
var UserName = document.getElementById('txtUserName').value;
var PWD = document.getElementById('txtUserPWD').value;
$.ajax({
type: "GET",
url: "http://192.168.200.56/ChatApp.asmx/UserLogin?u_name="+UserName +"&user_pwd="+PWD,
datatype:"html/xml",
success: function (xml) {
//alert(xml.find("string").text());
console.log(xml);
},
failure: function(Response) {
alert(Response.d);
}
});
}
这个ajax调用的响应是:
<string xmlns="http://tempuri.org/">"true"</string>
我希望这只是正确或错误,有人可以帮我弄清楚我在这里失踪了什么。提前致谢。
答案 0 :(得分:0)
您可以使用Response.Write()。在您的WebMethod中:
if (u_name == "unicolumn" && user_pwd=="admin")
{
Response.Write("true");
}
else
{
Response.Write("false");
}
然后,在ajax调用中:
...
success: function (xml) {
if (xml.responseText == "false") {
(your code)
}
},