1
While consuming a webservice an external URL via the link in the browser http://api.postmon.com.br/v1/cep/30640-240 returns the following JSON message:
{"complement": "from 9201 to the end - u00edmpar side (even side belongs a(o) Contagem)", "bairro": "Barreiro", "cidade": "Belo Horizonte", "patio": "Avenida Teresa Cristina", "estado_info": {"area_km2": "586.522,122", "codigo_ibge": "31", "name": "Minas Gerais"}, "cep": "30640240", "city_info": {"area_km2": "331,401", "codigo_ibge": "3106200"}, "status": "MG"}
How I can recover this data?
I’ve been using the Code:
<asp:TextBox ID="txtCep" runat="server"></asp:TextBox>
<asp:Button OnClientClick="buscarCep();" ID="btnCep" runat="server" />
<script type="text/javascript">
function buscarCep() {
var cep = $("#<%=txtCep.ClientID%>").val();
var url = "http://api.postmon.com.br/v1/cep/" + cep;
$.ajax({
url: url,
data: "{}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
var dados = JSON.parse(data.d);
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
}
</script>
More has generated me the following error.
Xmlhttprequest cannot load http://api.postmon.com.br/v1/cep/30640-240. In the 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost:50553' is therefore not allowed access. The Response had HTTP status code 405.
Friend, I edited my answer, from a look
– Thomas Lima
Thomas already has in my master page the same jquery.
– Marconi
Do you use Firebug or another similar??? If so, have you checked for any errors in the Console?
– Thomas Lima
I edited the question @Thomas Lima
– Marconi
Same problem you gave here... change the call function, instead of using $.ajax, use $.getJSON
– Thomas Lima