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