I'm implementing integration with a WS that fetches data based on cnpj .
When querying WS and requesting a callback
, it returns me the following ERROR:
Uncaught SyntaxError: Unexpected token:
I think you're having a misinterpretation of JSon .
The code I'm using is in this repo :
<html>
<head>
<title>CNPJ Webservice</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Adicionando Javascript -->
<script type="text/javascript" >
function meu_callback(conteudo) {
//Atualiza os campos com os valores.
document.getElementById('txtRazao').value=(conteudo.nome);
}
function pesquisacep(valor) {
//Nova variavel "cep" somente com d�gitos.
var cnpj = valor;
//Cria um elemento javascript.
var script = document.createElement('script');
//Sincroniza com o callback.
script.src = '//receitaws.com.br/v1/cnpj/'+ cnpj + '/?callback=meu_callback';
//Insere script no documento e carrega o conte�do.
document.body.appendChild(script);
};
</script>
</head>
<body>
<!-- Inicio do formulario -->
<form method="get" action=".">
<label>Cep:
<input name="txtCNPJ" type="text" id="txtCNPJ" value=""
onblur="pesquisacep(this.value);" /></label><br />
<label>Nome:
<input name="txtRazao" type="text" id="txtRazao" size="60" /></label><br />
</form>
</body>
</html>