3
I’m trying to calculate the mail freight via javascript, but when I do the test does not pull the data and returns me the error
Xmlhttprequest cannot load http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo?nCd…&nVlDiametro=0&sCdMaoPropria=s&nVlValorDeclarado=200&sCdAvisoRecebimento=s. Response to preflight request doesn’t pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'null' is therefore not allowed access.
Below is the js function 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 dataType to "jsonp" it returns the xml but I don’t know how I could get this information:
Uncaught Syntaxerror: Unexpected token <
Possible duplicate of Access-Control-Allow-Origin jQuery Ajax
– NoobSaibot