在javascript Ajax调用中从web服务中的XMLDocument获取响应。。。?

在javascript Ajax调用中从web服务中的XMLDocument获取响应。。。?,javascript,ajax,web-services,asmx,webmethod,Javascript,Ajax,Web Services,Asmx,Webmethod,我正在从服务器调用一个.asmxweb服务,它调用得很好,它返回XMLDocument中的响应,我只需要像TRUE或FALSE这样的结果 service.cs文件代码为: [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public string UserLogin(string u_name,string user_pwd) { st

我正在从服务器调用一个.asmxweb服务,它调用得很好,它返回XMLDocument中的响应,我只需要像TRUE或FALSE这样的结果

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>
“true”
我希望这是真是假,有人能帮我找出我在这里遗漏了什么。提前谢谢

您可以使用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) 
       }
},

它是.asmx文件中的一个web方法,因此我无法像这样编写响应;