When consuming a webService from an external URL through the link in the browser link returns the following JSON message:
{"add-in": "from 9201 to the end - even side (even side belongs to the "Count"), "neighborhood": "Barreiro", "city": "Belo Horizonte", "public place": "Avenida Teresa Cristina", "estado_info": {"area_km2": "Zip": "31", "name": "Minas Gerais"}, "zip": "30640240", "city_info": {"area_km2": "331,401", "codigo_ibge": "3106200"}, "state": "MG"}
How can I recover this data?
I have used 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 the following error.
XMLHttpRequest can not load link . At the 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' link ' is therefore not allowed access. The response had HTTP status code 405.