title: PhoneGap application and WCF service on different domains
body: <p>I am designing an application for Android using PhoneGap, which basically calls a web-service which for now, it will contain a method which returns something (let's say a string) as a return value. Finally, I want the web-service to handle queries which I am going to do against my Windows Azure database.</p>
  
  <p>My choice of a web-service was the Ajax-Enabled WCF Service. Was this the right choice?</p>
  
  <p>I tried a simple application to see how this works. First, I created a new project in Visual Studio and then created an Ajax-Enabled WCF Service. I added just one simple method:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "GET", ResponseFormat= WebMessageFormat.Json)]
  public string GetName()
  {
      return "Hello world";
  }
  </code></pre>
  
  <p>I didn't modify the Web.config, at all.</p>
  
  <p>Then, I opened Eclipse and created a new PhoneGap Android application with just a textbox and a button. Everytime, this button is clicked, the web-service will be called and the return value will be displayed in the textbox by using the following method:</p>
  
  <pre><code>$('#button').click(function(){
      $.ajax({ 
      type: "GET",     
      url: "http://localhost:11634/MobileService.svc/GetName",     
      contentType: "application/json",     
      dataType: "json",
      success: function (result) {     
          $("#textbox").text(result);     
      },             
      error: function (textStatus) {     
          $("#textbox").text(textStatus);
      }     
      });
  });
  </code></pre>
  
  <p>When I tried using this method, I get the following error in Firefox: <code>"NetworkError: 405 Method Not Allowed</code>. I then tried to change the data type to <code>jsonp</code> and added the following line before the AJAX call in order to allow cross domain requests:
   <code>$.support.cors = true;</code>. Now in Firefox, I get this error: </p>
  
  <pre><code>SyntaxError: invalid label
  {"d":"Hello world"}
  </code></pre>
  
  <p>Can you please guide me, on whether or not I am using the right methods and on how to handle the cross domain issues please?</p>