1
People I’m trying to get a response from an API of mine as JSONP but not the right one. Code ajax is this:
$.ajax({
type: 'GET',
url: url,
async: false,
contentType: "application/json",
dataType: 'jsonp',
complete: function(data) {
console.log(data);
}
});
Return is this of the console:
This is AJAX’s return response:
How do I recover these values in Jquery?
Thank you
var codigo = data[0].codigo
?– Sergio
@Sergio gave the following error: Uncaught Typeerror: Cannot read Property 'codigo' of Undefined
– Joao Nivaldo
Okay, and what gives
console.log(typeof data, data);
?– Sergio
@Sergio gives the answer that is in the first image I sent there in doubt.
– Joao Nivaldo
Instead of
complete: function(data) {
forehead withsuccess: function(data) {
– Sergio
@Sergio the strange also is that it does not enter the Success only in error, even the header stating status code 200 as the first picture shows. I no longer know what I did wrong. The hard that for example if I use POSTMAN and access the same API address everything comes back right. It could be because I’m running locally and accessing an external URL?
– Joao Nivaldo
And are you sure it’s jsonp? the answer seems to me json... testa dataType: 'json',
– Sergio
With JSON the following error: Xmlhttprequest cannot load http://testejn.hosting desites.ws/api/bairros/16. No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost:8080' is therefore not allowed access. Try to access via POSTMAN this URL and you will see that this right.
– Joao Nivaldo