如何修复startWith不在chrome中工作

时间:2014-12-08 08:12:17

标签: javascript ajax google-chrome

我正在使用Ajax使用我的代码

来检查DB中是否有可用的日期
 var url = "ValidateDateFromDB.jsp?cdate="+selecteddate.value;
    if (window.XMLHttpRequest)
    req = new XMLHttpRequest();
    else if (window.ActiveXObject)
    req = new ActiveXObject("Microsoft.XMLHTTP");
    req.open("GET", url, true);
    req.onreadystatechange =callback;
    req.send(null);


 function callback()
    {
      if (req.readyState == 4)
       {
        if (req.status == 200) 
          {
              var message = req.responseText;
              alert(message);  
              if(message.startsWith("Available"))
                {
                   alert("Availabe");

                }
               else
                {
                   alert("Not Availabe");
                }


          }
        }
     }

我的输出如下图所示

enter image description here

它在firefox中工作正常,但在chrome中没有工作。我检查了startsWith只能使用40以上版本的chrome。所以为了解决这个问题,我使用了==这样的操作,

if(message=="Available")
    {
      alert("Availabe");

    }
else
   {
     alert("Not Availabe");
   }

但是这段代码总是转到我知道原因的其他部分。

有人告诉我如何解决这个问题?

0 个答案:

没有答案