title: How To Trigger Azure Automation Web Hook From A Web Browser AJAX Call?
body: <p>I have an Azure web hook on an Azure Automation script which accepts requests to do stuff from the web. </p>
  
  <p>The following little Powershell program tests the web hook and it works fine:</p>
  
  <pre><code>$uri = "https://s10events.azure-automation.net/webhooks?token=my_super_secret_token"
  $headers = @{"From"="jay@exampel.com";"Date"="05/28/2017 14:49:00"}
  $params = @{"customerName"="Giovanni Pasqualovich"; "customerEmail"="giovanni.pasqualovich@company.com"; "dataLocation"="UK South"}
  $body = ConvertTo-Json -InputObject $params
  $webresp = Invoke-WebRequest -Method Post -Uri $uri -Headers $headers -Body $body -Verbose
  </code></pre>
  
  <p>I want to call the web hook from a web page. To do that, I have the following code in a HTML page:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      function postWebHook() {
         var chdata = {};
         chdata['customerEmail'] =  "giovanni.pasqualovich@company.com"; 
         chdata['customerName']= "Giovanni Pasqualovich"; 
         chdata['dataLocation'] = "UK South";
  
         jdata = JSON.stringify(chdata);     
  
         alert("JSON data: "+ jdata);
          $.ajax({
                  url : "https://s10events.azure-automation.net/webhooks?token=my_super_secret_token",
                  type: "POST",
                  data: jdata,
                  contentType: "application/json; charset=utf-8",
                  dataType   : "json",
                  success    : function(){
                      console.log("Commit Hook to create customer database called");
                      alert("Success");
                  },
                  error : function(XMLHttpRequest, textStatus, errorThrown) { 
                      alert("Status: " + textStatus);
                  }      
              });     
      }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="div1"&gt;&lt;h2&gt;DO SOMETHING&lt;/h2&gt;&lt;/div&gt;
  
  &lt;form action=""&gt;
       &lt;input type="submit" accesskey="s" value="Submit Order" onclick="postWebHook()"&gt;
  &lt;/form&gt; 
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I loaded this page into a web browser from my local file system, and clicked on the form button. 
  Nothing happened. The Azure Automation script was not called. In Google Chrome, going to More Tools -> Developer Tools
  showed me the network view in the browser. Running that script caused a red message of type xhr to appear, 
  but the status was (canceled). Once I clicked the last "alert" dialog from my web page, the error disappeared 
  from the network view. </p>
  
  <p>What do I need to do to test my web hook from a browser with Javascript/Ajax code? The code is going to run on one
  web site, but the POST request for the web hook goes to s10events.azure-automation.net. I appreciate any help that
  I can get. </p>
  
  <p>-------------  UPDATE  Jan 5, 2018  ----------------</p>
  
  <p>I checked the network traffic more closely, and the call is sending an OPTIONS HTTP message instead of a POST. Apparently that is used by browsers to pre-flight a request. How do I disable this?</p>
  
  <p>I also installed the FireFox REST Client, and I was able to run the message fine. </p>