title: MVC WebAPI Javascript possible cross domain issue
body: <p>I'm in the process of building a WebApi - have tested locally, and all works fine.  Deployed to my host machine, and after a few issues of ensuring the ajax call was using the right url to access the webapi, I have hit a problem.</p>
  
  <p>Here's my Razor code that shows the jQuery AJAX call:</p>
  
  <pre><code>    string myUrl = Url.Action("Index","Home", null, Request.Url.Scheme, null);
  
  
  &lt;script type="text/javascript"&gt;
      function findByVrm() {
          $('#response').text('Searching...');
  
          var uri = '@myUrl' + 'api/vehicle';
          var id = $('#vrm').val();
          var call = null;
  
          // Setup a 'call' object differently depending upon if we want to return
          // JSON data or XML data
          if ($('#rbJson').prop('checked')) {
              call = {
                  type: 'GET',
                  url: uri + '?vrm=' + id
              };
          } else {
              call = {
                  type: 'GET',
                  url: uri + '?vrm=' + id,
                  dataType: 'xml',
                  accepts: {
                      xml: 'text/xml',
                      text: 'text/plain'
                  }
              };
          }
  
          // Perform the API call
          $.ajax(call)
              .success(function (response, textStatus, jqXHR) {
                  showStatus(jqXHR);
  
                  if ($('#rbJson').prop('checked')) {
                      $('#response').html(vkbeautify.json(response));
                      $('#status').text('Vehicle Found: '+response.data.idscode);
                  } else {
                      $('#response').text(vkbeautify.xml(jqXHR.responseText));  // text version of the XML
                  }
  
  
              })
              .fail(function (jqXHR, textStatus, err) {
                  showStatus(jqXHR);
                  $('#response').text('');
              });
      }
  
      function showStatus(jqXHR) {
          var msg = 'Status: ' + jqXHR.status + '/' + jqXHR.statusText;
          $('#status').text(msg);
  
          return;
      }          
  &lt;/script&gt;
  </code></pre>
  
  <p>The HTML is purely a text box with the id of 'vrm', this is the search string, a button which calls the findByVrm() javascript function,  a radiobutton that dictates if the call should return JSON or XML data,  a textbox to display the status of the call, and a textarea to display the content.</p>
  
  <p>When run on localhost, this all works perfectly.  When deployed to the remote host machine, and a call constructed in Fiddler,  it works perfectly.  </p>
  
  <p>However when browsing to this page on the remote host machine and making the call through the above code...  the API method is called (I have log messages that show it was called, and that a response was sent back),  the status is updated and shows 200/OK  - indicating to me that the call succeed,  however JSON or XML data does not appear to have been returned in this instance (or if it has been returned, is not visible).</p>
  
  <p>Having researched this on stackoverflow and other sites, I believed it was a 'cross-domain' issue, and have followed other posts about implementing a CORS handler  - and yet, when the webapi is hosted on the remote server and the above Javascript is called, I am still not seeing the response data.</p>
  
  <p>I took the CORS handler code from here: <a href="https://stackoverflow.com/questions/13018020/mvc-webapi-cross-domain-post">CORS Handler</a></p>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <p>EDIT:   Further to the post above and the questions asked below - I've created a JSFiddle to see if I could replicate the issue that I was seeing in isolation - <a href="http://jsfiddle.net/theboffin/4HvM7/" rel="nofollow noreferrer">Here is the Fiddle</a> </p>
  
  <p>The Fiddle WORKS  -- however the above Javascript isn't working - so my initial conclusion here is the vkbeautify is failing, and consequentially quietly exiting the findByVrm() method.</p>
  
  <p>I will perform a bit more testing on this;  but I'd like to thank everyone who's spent time looking at this with me.</p>
  
  <hr>
  
  <p>EDIT: So by removing the vkbeautify.json() call and replacing with a JSON.stringify() and placing the result of that into the textarea  -- this works.</p>
  
  <p>I'm not sure why vkbeautify worked on response data when I was running it in localhost through Visual Studio, but it's irrelevant  -- it'd be nice to be able to 'pretty print' both the JSON and XML responses - but there are other solutions I can look into for that;  this is just a test-bed application, so as long as I can see the response, that's all I need.</p>
  
  <p>Again thank you for all your help. </p>