title: why settimeout() anonymous function not call the function in javascript?
body: <p>I write code below to call external web services it's not worked in safari browser without debugger.so as solution i add the settimeout() function to delay the xhr.send() function.Real problem is below described:<br>
  I trying to call alertFunc after 2 second but settimeout() function is not call the alertFunc.Can you help me to solve it.
  I define below code my wordpress footer.php file. </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  debugger;
  var xhr;
        // Create the XHR object.
        function createCORSRequest(method, url) {
  
             xhr = new XMLHttpRequest();
             if ("withCredentials" in xhr) {
               // XHR for Chrome/Firefox/Opera/Safari.
  
          xhr.open(method, url, true);
  
  
             } else if (typeof XDomainRequest != "undefined") {
               // XDomainRequest for IE.
               xhr = new XDomainRequest();
               xhr.open(method, url);
             } else {
               // CORS not supported.
               xhr = null;
             }
             return xhr;
           }
  
      function alertFunc(xh) {
          debugger;
             var xh1=xh;
             xh1.send();
         alert("Thank you for contacting us!");
  
      }
          function saveContactData() {
              var name = document.getElementById('name').value;
              var petname = document.getElementById('petname').value;
              var weight = document.getElementById('weight').value;
               var breed = document.getElementById('breed').value;
              var phone = document.getElementById('phone').value;
              var email = document.getElementById('email').value;
              var findus = document.getElementById('findus').value;
              var location = document.getElementById('location').value;
              var comments = document.getElementById('comments').value;
  
  
  
              var item = {
                  "PetInquiryId": -1,
                  "ClientName": name,
          "Weight":weight,
                  "Breed":breed,
                  "PhoneNumber": phone,
                  "PetName": petname,
                  "Email": email,
                  "Comments": comments,
                  "Location": location,
                  "FindUsName": findus,
  
              };
          debugger;
               var url = "http://sitename/api/Controllername/functionnme?item=" + JSON.stringify(item);
              var xhr = createCORSRequest("POST",url);   
  
          //xhr.send();
           setTimeout(alertFunc(xhr), 25000);
  
  
         document.getElementById("myForm").reset();
  
  
          }
  
  
      &lt;/script&gt;
  </code></pre>