Ajax CrossDomain Error: "Unexpected token:"

0

When I bring data from an AFIP service, I get the error  "Unexpected token:".

Apparently the type of data it returns is incorrect, some solution? thanks

My Js code is as follows:

 var WSAFIP="https://soa.afip.gob.ar/sr-padron/v2/persona/";
 $.ajax({
                    type: "GET",
                    dataType: "jsonp",
                     jsonp: 'jsonp',
                      jsonpCallback: 'callback',
                    contentType: 'text/json',
                   //contentType: 'text',
                    callback: function (result) {
                        if (result != null && result != undefined) {
                            for (var i = 0; i <= result.length - 1; i++)
                                data.push(result[i].word);
                        }
                    },

                     //  crossDomain: true,
                   // data: { index: at.toString(), entities: en.toString(), word: wo.toString() },
                    url:  WSAFIP + $cuit.val()+ '?format=json&callback=w',//'?jsonp=callme',
                    success: function (result) {
                        if (result != null && result != undefined) {
                            for (var i = 0; i <= result.length - 1; i++)
                                data.push(result[i].word);
                        }
                    },

                error: function(data) {
                var s=data;
                },
                });

Json returned:

{"success":true,"data":{"idPersona":33709585229,"tipoPersona":"JURIDICA","tipoClave":"CUIT","estadoClave":"ACTIVO","nombre":"GOOGLE ARGENTINA S.R.L.","domicilioFiscal":{"direccion":"MOREAU DE JUSTO A.AV 350 Piso:2","codPostal":"1107","idProvincia":0},"idDependencia":10,"mesCierre":12,"fechaInscripcion":"2006-04-07","fechaContratoSocial":"2006-03-29","impuestos":[353,218,10,30,25,211,103,217,301],"actividades":[731009,620900,711003],"caracterizaciones":[68,72,255]}}
    
asked by Andromeda 27.12.2016 в 17:25
source

1 answer

2

To enable CORS you can use the option crossDomain

So for example:

$('#consultar').on('click', function() {
  var cuit = $('#cuit').val();
  
  $.ajax({
    url: 'https://soa.afip.gob.ar/sr-padron/v2/persona/'+cuit+'?format=json',
    dataType: 'JSON',
    crossDomain: true
  })
  .done(function(response) {
    if (response.success) {
      console.log('Exito: ' + JSON.stringify(response.data));
    } else {
      console.log('ERROR: ' + response.error.mensaje);
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
CUIT: <input type="text" id="cuit" />
<button id="consultar">CONSULTAR</button>
    
answered by 27.12.2016 / 17:47
source