Request problem - Phonegap + Ajax [duplicate]

1

I was doing a test to test the phonegap, however I am not able to make an Ajax request in the app, but the request works in the browser.

$( "#botaoBusca" ).click(function(){

var cep = $( "#cep" ).val();

$.getJSON('https://viacep.com.br/ws/'+cep+'/json/?callback=?', function(data) {

var endereco =
   { rua    : data.logradouro,
     cidade : data.localidade,
     uf     : data.uf
   };

$( "#endereco" ).text("Você mora na "+endereco.rua+", "+endereco.cidade+" - "+endereco.uf);

});
});

HTML:

</head>
 <body>
   <div class="container text-center">
   <div class="row">
    <h1>Olá, AJAX</h1>

            <label>Digite o seu cep:</label>   
            <input id="cep" type="text" pattern="\d{8}" maxlength="8"><br>
            <button class="btn btn-primary" id="botaoBusca" type="button">Buscar</button>    

            <h3 id="endereco"></h3>
        </div>
    </div>    
    <script src="js/jquery-1.12.2.min.js"></script>
    <script src="js/jquery.mobile-1.4.5.min.js"></script>
    <script src="js/ajax.js"></script>
</body>

Thank you

    
asked by anonymous 12.05.2016 / 05:45

1 answer

-1

Have you allowed the application to use the internet? If you have not put the android does not let the application use internet resources, so your code will not communicate with the server.

And if you're using Cordova 4.1+ (or higher) might be a problem with WhiteList, check it out to see if it's installed.

    
20.08.2016 / 22:51