title: cors trouble calling web service from jquery
body: <p>I've created a web service with axis2 and I've deployed in apache tomcat 7 with eclipse. </p>
  
  <p>This is the class which I converted in a web service. It's just an echo:</p>
  
  <pre><code>package test.org;
  public class TestWS {
      public String echo(String s){
          return ("You typed: " + s);
      }
  }
  </code></pre>
  
  <p>If I try this web service from Eclipse, adding the wsdl in Web Services Explorer it works perfectly, but the problem comes when I try to consume this ws from jquery.
  I can access without any problem to the wsdl, which is located at:   <code>http://localhost:8080/SimpleWS/services/TestWS?wsdl</code></p>
  
  <p>But, when I try this code, the following error happen: XMLHttpRequest cannot load <code>http://localhost:8080/SimpleWS/services/TestWS</code>. Origin null is not allowed by Access-Control-Allow-Origin.</p>
  
  <p>I've been reading about CORS and about including in the server side some code like this:Access-Control-Allow-Origin: *, but since I've deployed my ws directly with eclipse I don't know how to do this and I'm not sure if this is my problem.</p>
  
  <p>Thank you in advance!!</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;h3&gt;Web service example&lt;/h3&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
  function callWS() {
      var soapmessage = "&lt;soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " +
                                      "xmlns:q0='http://org.test' xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
                                      "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'&gt;";
                        soapmessage += "&lt;soapenv:Body&gt;";
                        soapmessage += "&lt;q0:echo&gt;";
                        soapmessage += "&lt;q0:s&gt;HELLO&lt;/q0:s&gt;";
                        soapmessage += "&lt;/q0:echo&gt;";
                        soapmessage += "&lt;/soapenv:Body&gt;";
                        soapmessage += "&lt;/soapenv:Envelope&gt;";
                        alert(soapmessage);
                        $.ajax({
                            type: 'POST',
                            url: 'http://localhost:8080/SimpleWS/services/TestWS',
                            data: soapmessage,
                            contentType: "application/xml; charset=utf-8",
                            dataType: "xml",
                            success: function (data) {
                               alert(data);
                            },
                            error: function (data) {
                                alert("error" + data.d);
                            }
                       });
                       alert("Form Submitted");
  }
  
  &lt;/script&gt;
  
  &lt;form method="post" action=""&gt;
      &lt;input type="button" onclick="callWS()" value="execute" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>