title: Saving Data with Ajax Call to WebService with Json as Parameter is not working In Cordova Project for Android
body: <p>I am trying to make a Anroid Mobile Application to Save Data to a Remote SQL Database. I am using Cordova Project in Visual Studio 2015. I have a Webservice which is working fine and taking Name, Phone &amp; Profile information and saving data in SQL Server properly. Now I am trying to call this WebService from Android Mobile Application but $Ajax Call to webservice is not working. The control is not reaching to the Webservice. </p>
  
  <p>I have already added WhiteSpace Plugin but its still not working.</p>
  
  <p>Here is the original html file</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"&gt;      
          &lt;meta name="format-detection" content="telephone=no"&gt;
          &lt;meta name="msapplication-tap-highlight" content="no"&gt;
          &lt;meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"&gt;
          &lt;script src="../scripts/jquery-3.1.0.min.js"&gt;&lt;/script&gt;
          &lt;script src="../scripts/jquery.mobile-1.4.5.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" charset="utf-8"&gt;
              function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); }
              function onDeviceReady() { alert("Device is Ready to User"); }
              function SaveContact() {
                  var Contact = new Object();
                  Contact.Name = "Harvinder";
                  Contact.Phone = "9819862717";
                  Contact.Profile = "Director"
                  var myData = JSON.stringify(Contact);
                  var myURL = "http://gsecurity.net/JsonDAL.asmx/SaveContact";
                  alert(typeof (myData));
                  $.ajax({
                      type: "POST", url: myURL, data: myData, contentType: "application/json; charset=utf-8", dataType: "json",
                      success: function (msg) { alert("Success"); },
                      error: function (e, status) { alert("Failed:"  + e.statusText); }
                  });}
          &lt;/script&gt; 
      &lt;/head&gt;
      &lt;body onload="onLoad()"&gt;
          &lt;h1&gt;Call Ajax to Save Json Data with WebService&lt;/h1&gt;
          &lt;button onclick="SaveContact();"&gt;Click Here to Save Test Contact&lt;/button&gt;
          &lt;script type="text/javascript" src="cordova.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="scripts/platformOverrides.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="scripts/appBundle.js"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the modified code as per suggestions which is still not working</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Security-Policy" content="default-src *; style-src * 'unsafe-inline' 'unsafe-eval'; script-src * 'unsafe-inline' 'unsafe-eval'"&gt;
      &lt;meta name="format-detection" content="telephone=no"&gt;
      &lt;meta name="msapplication-tap-highlight" content="no"&gt;
      &lt;meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"&gt;
      &lt;script type="text/javascript" charset="utf-8"&gt;
              document.addEventListener("deviceready", onDeviceReady, false);
              function onDeviceReady() { alert("Version 1.10 is Ready"); }
              $.support.ajax = true;
              $.support.cors = true;
              $.mobile.allowCrossDomainPages = true;
              function SaveContact() {
                  var Contact = new Object();
                  Contact.Name = "Harvinder";
                  Contact.Phone = "9819862717";
                  Contact.Profile = "Director";
                  var myData = JSON.stringify(Contact);
                  var myURL = "http://gsecurity.net/JsonDAL.asmx/SaveContact";
                  alert("DataType:" + typeof (myData));
                  $.ajax({
                      type: "POST", contentType: "application/json", dataType: "json",
                      url: myURL, data: myData, allowCrossDomainPages: true,                 
                      success: function (msg) { alert("Success"); },
                      error: function (e, status) { alert("Failed:"  + e.statusText); }
                  });
                  alert("Completed");
              }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h2&gt;Call Ajax to Save Json Data with WebService&lt;/h2&gt;
      &lt;button onclick="SaveContact()"&gt;Click Here to Save Test Contact&lt;/button&gt;
      &lt;script type="text/javascript" src="../scripts/jquery-3.1.0.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="../scripts/jquery.mobile-1.4.5.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="cordova.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="scripts/platformOverrides.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="scripts/appBundle.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My Webservice is Here which is working fine when accessed directly by url</p>
  
  <pre><code>Imports System.Web.Services
  Imports System.Web.Services.Protocols
  Imports System.ComponentModel
  Imports System.Data
  Imports System.Data.SqlClient
  
  &lt;System.Web.Script.Services.ScriptService()&gt;
  &lt;System.Web.Services.WebService(Namespace:="http://tempuri.org/")&gt;
  &lt;System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt;
  &lt;ToolboxItem(False)&gt;
  Public Class JsonDAL
      Inherits System.Web.Services.WebService
      &lt;WebMethod&gt;
      Public Function SaveContact(Name As String, Phone As String, Profile As String) As String
          Try
              Dim ConStr = ConfigurationManager.ConnectionStrings("Data").ConnectionString
              Dim Con = New SqlConnection(ConStr)
              Dim Qry = "INSERT INTO Contacts (Name,Phone,Profile) VALUES ('" + Name + "','" + Phone + "','" + Profile + "')"
              Dim Cmd = New SqlCommand(Qry, Con)
              Cmd.CommandType = CommandType.Text
              Con.Open()
              Cmd.ExecuteNonQuery()
              Con.Close()
              Return "Done"
          Catch ex As Exception
              Return ex.Message
          End Try
  
      End Function
  
  End Class
  </code></pre>