title: How to call asp.net web services using ajax from cross domain
body: <p>i am developing mobile application using javascript,html,css(cross platform technology),i have written a web services using asp .net, i want to fetch the data from web services and display into client side using javascript/jquery. we point to web services and display the result but this is work in IE(internet explorer) only, we get the result as "true" response from server but in other browser (Mozilla,chrome) it does not work,we get result "false" as response from server.where as i am expecting result come as "true" in all the browser but its not happening.below i have given all the code that i have used.  </p>
  
  <p>WebService.asmx.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Services;
  
  /// &lt;summary&gt;
  /// Summary description for WebService
  /// &lt;/summary&gt;
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
  [System.Web.Script.Services.ScriptService]
  public class WebService : System.Web.Services.WebService {
  
      [WebMethod]
      public bool GetValue(string id,string pwd)
      {
          string userid = "abc";
          string password = "xyz";
          if (userid==id &amp;&amp; password==pwd)
          {
              return true;
          }
          else
          {
              return false;
          }
      }
  
  }
  </code></pre>
  
  <p>Web.config </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
  &lt;configuration&gt;
      &lt;system.web&gt;
          &lt;compilation debug="true" targetFramework="4.0"/&gt;
      &lt;/system.web&gt;
      &lt;system.webServer&gt;
          &lt;httpProtocol&gt;
              &lt;customHeaders&gt;
                  &lt;add name="Access-Control-Allow-Origin" value="*"/&gt;
                  &lt;add name="Access-Control-Allow-Headers" value="Content-Type"/&gt;
              &lt;/customHeaders&gt;
          &lt;/httpProtocol&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>HTML page Code </p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;title&gt;
      &lt;/title&gt;
      &lt;script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
     &lt;script&gt;
         function JsonTest2() {
  jQuery.support.cors = true;
             $.ajax({
                 type: 'POST',
                 url: "http://10.16.10.35/webservice_test/WebService.asmx/GetValue",
                 data: '{"id":"vipul","pwd":"borole"}',
                 contentType: 'application/json; charset=UTF-8',
                 dataType: 'json',
                 async: false,
                 success: function (msg) {
                     alert(msg.d);
                 },
                 error: function (msg) {
                     alert('failure');
                     alert(msg);
                 }
             });
         }
     &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;input id="Button1" type="button" value="button" onclick="javascript:JsonTest2();" /&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>please help me to call this web service from all the browser i am not able to understand why it returning false</p>