title: Cordova app ajax call to localhost fails. ::ERR_CONNECTION_REFUSED
body: <p>I've got an node.js (express) webapp running on localhost:3000. I am now trying to develop a mobile app using cordova.</p>
  
  <p>I've got a route defined in my express app 'localhost:3000/tweets' which when called gets some tweets using twitter API and send them back as json object. Everythinngs works very fine using web app however I am struggling to make the same ajax call from a mobile app. To allow requests from other hosts I've added this to my edxpress app.js:
  EDIT: i use cors middleware now:</p>
  
  <pre><code>  app.use(cors());
  </code></pre>
  
  <p>In my cordova app:</p>
  
  <p>meta tag:</p>
  
  <pre><code>&lt;meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"&gt;
  </code></pre>
  
  <p>config.xml</p>
  
  <pre><code>    &lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;widget id="&lt;id...&gt;" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"&gt;
      &lt;name&gt;appname&lt;/name&gt;
      &lt;description&gt;
          A twitter search app.
      &lt;/description&gt;
      &lt;author email="dev@cordova.apache.org" href="http://cordova.io"&gt;
          Apache Cordova Team
      &lt;/author&gt;
      &lt;content src="index.html" /&gt;
      &lt;access origin="*" /&gt;
      &lt;allow-intent href="http://*/*" /&gt;
      &lt;allow-intent href="https://*/*" /&gt;
      &lt;allow-intent href="tel:*" /&gt;
      &lt;allow-intent href="sms:*" /&gt;
      &lt;allow-intent href="mailto:*" /&gt;
      &lt;allow-intent href="geo:*" /&gt;
      &lt;platform name="android"&gt;
          &lt;access origin="*" /&gt;
          &lt;allow-intent href="market:*" /&gt;
      &lt;/platform&gt;
      &lt;platform name="ios"&gt;
          &lt;allow-intent href="itms:*" /&gt;
          &lt;allow-intent href="itms-apps:*" /&gt;
      &lt;/platform&gt;
      &lt;engine name="android" spec="^6.2.3" /&gt;
      &lt;plugin name="cordova-plugin-camera" spec="^2.4.1" /&gt;
      &lt;plugin name="cordova-plugin-whitelist" spec="^1.3.2" /&gt;
  &lt;/widget&gt;
  </code></pre>
  
  <p>In the index.html file i link 'querySender.js' file at the bottom of body:</p>
  
  <pre><code>    &lt;script type="text/javascript" src="js/querySender.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>And finally, content of 'querySedner.js'</p>
  
  <pre><code>$(document).ready(function(){
  
    $('#btn_send').on('click', function(){
      console.log("app is now sending query!");
      $.ajax({
          type: 'POST',
          url: 'http://127.0.0.1:3000/tweets',
          data: {name:"test_name",lastname:"last_name"},
          dataType:'json',
          success: function(dataR){
            var date = new Date();
            console.log("POST success recorded at: ",date.getTime());
            if (!dataR){
            console.log("No Data received");
            }else{
                console.log("DataR: ",dataR);
            }
          },
          error: function(XMLHttpRequest, textStatus, errorThrown) {
            console.log("Status: " + textStatus+" error:"+ errorThrown);
          },
          timeout:5000
        });
  
    });
  });
  </code></pre>
  
  <p>using WebStrom IDE i tried to run index.html in chrome (it runs it on  localhost:63342) the request succeeds and data is delivered as expected.</p>
  
  <p>however is emulate the app using android emulator when i press the button i get:</p>
  
  <pre><code>POST http://127.0.0.1:3000/tweets net::ERR_CONNECTION_REFUSED -- jquery-3.2.1.min.js:4
  </code></pre>
  
  <p>Basically. I'm running my node.js(express) server locally and would like to make ajax calls to it from cordova app on android emulator. What did I get wrong?</p>