I'm trying to make the freight calculation of the post via javascript, but when I do the test it does not pull the data and it returns the error to me
XMLHttpRequest can not load link ... & nVlDiametro = 0 & sCdMaoPropria = s & nVlValueDeclarado = 200 & sCdAvisoReceiving = s. Response to preflight request does not pass access control check: In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Below is the function in js that I'm using.
function calcWsCorreios{
var sendjson = {
"nCdEmpresa":"",
"sDsSenha":"",
"nCdServico":"41106",
"sCepOrigem":"37540000",
"sCepDestino":"37540000",
"nVlPeso":"1",
"nCdFormato":"1",
"nVlComprimento":"20",
"nVlAltura":"5",
"nVlLargura":"15",
"nVlDiametro":"0",
"sCdMaoPropria":"s",
"nVlValorDeclarado":"200",
"sCdAvisoRecebimento":"s"
}
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url:
"http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo",
data: sendjson,
dataType: "json",
success: function (data) {
console.log(data);
},
error:function (data,err) {
console.log(data);
console.log(err);
},
});
}
If I change the dataType to "jsonp" it returns the xml but I do not know how I could get this information:
Uncaught SyntaxError: Unexpected token