title: Can't call PHP file via AJAX (Cordova)
body: <p>I'm a beginner. I've been trying to develop an app using cordova/phonegap. I've made an example database and uploaded it on a free host, and did the same with the php file. I can retrieve data from the DB when on web/desktop, but it doesn't work on the emulator. What should I do?</p>
  
  <p>I've tried to discover what's happening: what I know so far is that the javascript file is ok, since a function of "alert" on it is working. I know my php files aren't working on phonegap because i've tried to update my db and it didn't work.</p>
  
  <p><strong>getDados.php (on a web host):</strong></p>
  
  <pre><code>&lt;?php
      header('Access-Control-Allow-Origin: *');
      header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
      //Conectando ao banco de dados
      $con = new mysqli("sql10.freemysqlhosting.net", "login_bd", "senha_bd", "nome_bd");
      if (mysqli_connect_errno()) trigger_error(mysqli_connect_error());
  
      //Consultando banco de dados
      $qryLista = mysqli_query($con, "SELECT * FROM usuarios");    
      while($resultado = mysqli_fetch_assoc($qryLista)){
          $vetor[] = array_map('utf8_encode', $resultado); 
      }    
  
      //Passando vetor em forma de json
      echo json_encode($vetor);
  ?&gt;
  </code></pre>
  
  <p><strong>index.html (on my local machine):</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="pt-br"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;AJAX, JSON E PHP&lt;/title&gt;
          &lt;script src="//code.jquery.com/jquery-1.11.2.min.js"&gt;&lt;/script&gt;
          &lt;script src="http://IP DA MÁQUINA LOCAL/geek_phonegap/www/ajax.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;table border="1" width="500"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;ID&lt;/th&gt;
                      &lt;th&gt;Usuario&lt;/th&gt;
                      &lt;th&gt;Senha&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody id="tabela"&gt;&lt;/tbody&gt;
          &lt;/table&gt;
          &lt;button onclick="funcao1()"&gt;Alert&lt;/button&gt;
      &lt;/body&gt;
      &lt;meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>ajax.js (local machine):</strong></p>
  
  <pre><code>function funcao1()
  {
      alert("Está chamando o arquivo ajax.js!");
  }
  
  $(document).ready(function(){
      $('#tabela').empty(); //Limpando a tabela
      $.ajax({
          type:'post',        //Definimos o método HTTP usado
          dataType: 'json',   //Definimos o tipo de retorno
          url: 'http://uniapp.orgfree.com/getDados.php',//Definindo o arquivo onde serão buscados os dados
          success: function(dados){
              for(var i=0;dados.length&gt;i;i++){
                  //Adicionando registros retornados na tabela
                  $('#tabela').append('&lt;tr&gt;&lt;td&gt;'+dados[i].id+'&lt;/td&gt;&lt;td&gt;'+dados[i].usuario+'&lt;/td&gt;&lt;td&gt;'+dados[i].senha+'&lt;/td&gt;&lt;/tr&gt;');
              }
          }
      });
  });
  </code></pre>