title: Calling WebService from Ajax/Javascript
body: <p>I am getting into a little jam here. I created a webservice using C#. When I Invoke the WebService it works fine. The Javascript seems to be hitting the webservice, breaking, and then follows through with the rest of the operation. I think this is a matter of me calling the WebService wrong. I've searched all over and have found tons of different examples, however, none of them seem to work.</p>
  
  <p>If you go to <a href="http://success.darkslidedesign.com" rel="nofollow">http://success.darkslidedesign.com</a> it triggers test.js which then calls my web service located here: <a href="http://www.darkslidedesign.com/services/ms_Alert.asmx" rel="nofollow">http://www.darkslidedesign.com/services/ms_Alert.asmx</a></p>
  
  <p>Here is the test.js code - </p>
  
  <pre><code>var xmlHttp;
  setTimeout("sendMessage('rory@careercheatcode.com');", 2000);
  function doUpdate()
  {
      if(xmlHttp.readyState===4){
          alert("Worked");
          }
      else{
          alert("Broke");
          }
  }
  function sendMessage(strTo)
  {
      try{
          // Opera 8.0+, Firefox, Safari
          xmlHttp = new XMLHttpRequest();
          } catch (e){
          // Internet Explorer Browsers
          try{
                  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
              } catch (e) {
                  try{
                      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                  } catch (e){
                      // Ajax is not supported
                      return false;
                  }
              }
      }   
      xmlHttp.open("post", "http://www.darkslidedesign.com/services/ms_Alert.asmx", true);    
      var params = "op=Sending_Email&amp;strEmailAddrFrom=rory@darkslidedesign.com&amp;strEmailAddrTo=" + strTo;
      xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-length", params.length);
      xmlHttp.setRequestHeader("Connection", "close");    
      xmlHttp.onreadystatechange=doUpdate;    
      xmlHttp.send(params);
      return false;
  }
  </code></pre>