js trim() sendHttp()用法

  function Trim(s) {
              return s.replace(/(^\s*)|(\s*$)/g, "");
          }

function ck(obj) {
            var strFlag = SendHttp("ShowHttp.aspx?name=" + Trim(obj.value)+"&flag=reg", "");

            if (strFlag == "1") {
                alert("该用户名已存在!");
                obj.value = "";
                obj.focus();
            }
        }
 function SendHttp(sAspFile, sSend) {
              if (navigator.onLine == false) {
                  //return "你现在处于脱机状态,请联机后再试!"
                  return "offline status now,please try again after on-line.";
              }
              var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

              xmlhttp.Open("POST", sAspFile, false);

              try {
                  xmlhttp.Send("<root>" + sSend + "</root>");

              }

              catch (exception) {
                  //alert("由于网络原因与服务器连接暂时中断,请重新登陆!")
                  alert("server busy now.");
              }
              // alert(xmlhttp.responseText)

              try {
                  var str11 = xmlhttp.responseText //系统错误: -1072896748。
              }
              catch (exception) {
                  if (exception.description.indexOf("-1072896748") > 0) {
                      str11 = ""
                      //alert("aa")
                  }

              }
              //if (str11.indexOf("-2147483638")!=-1) str11=""
              //alert(str11)
              return str11

          }

后台

 在pageload中写:

Response.Write(" ");//还回一个字符串

Response.End(); 

原文地址:https://www.cnblogs.com/peaceshow/p/2511535.html