title: Call ASP.NET web service from a different domain via javascript
body: <p>I want to call an asp.net web service's from a different domain with javascript. </p>
  
  <p>Ex :</p>
  
  <p>I have the site "www.abc.com", I want it to call the web service on "www.xyz.com" with some javascript I load from X domain.</p>
  
  <p>First I add the script with this :</p>
  
  <pre><code>document.write(unescape("%3Cscript src=%27http://myscript.com/script.js%27 type=%27text/javascript%27%3E%3C/script%3E"));
  </code></pre>
  
  <p>This is the <code>script.js</code> file :</p>
  
  <pre><code>$.ajax({
    type: "POST",
    url: "http://www.xyz.com/Service1.asmx/InsertIt",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    error: function (response) {
        alert(response);
    }
  });
  
  function OnSuccess(response) {
    alert(response.d);
  }
  </code></pre>
  
  <p>I know Cross-domain calls from within client-side code are a no-no in all major browsers. To achieve that, I think you can use CORS.</p>
  
  <blockquote>
    <p>Use CORS, ie. set Access-Control-Allow-Origin header to
    <a href="http://your-caller-domain.com" rel="nofollow">http://your-caller-domain.com</a> in the web</p>
  </blockquote>
  
  <p>In this example, I know the caller domain : www.abc.com. but in the real life, I will never know the caller domain. I know there's other way to do a Cross-Domain call, ex : JSONP. But this technique is really complexe (for me). </p>
  
  <p>So I am asking is there's an easy way to achieve a Cross-Domain call ? </p>