Problems in returning a JSONP

1

I'm trying to get a response from my API like JSONP but it's not right. Ajax code is this:

$.ajax({
            type: 'GET',
            url: url,
            async: false,
            contentType: "application/json",
            dataType: 'jsonp',
            complete: function(data) {
                console.log(data);
            }
        });

Return is this from the console:

ThisistheAJAXreturnresponse:

How do I retrieve these values in JQuery?

Thank you

    
asked by anonymous 25.09.2015 / 16:22

2 answers

0

Here's an example:

       $.ajax({
            type: 'GET',
            url: url,
            async: false,
            contentType: "application/json",
            dataType: 'jsonp',
            complete: function(data) {
                console.log(data[0].atributo);
            }
        });

Or if you returned a String as JSON:

       $.ajax({
            type: 'GET',
            url: url,
            async: false,
            contentType: "application/json",
            dataType: 'jsonp',
            complete: function(data) {
                var obj = jQuery.parseJSON( data );
                console.log(obj[0].atributo);                    
            }
        });

To get all the attributes of each array just do a simple for.

    
25.09.2015 / 19:43
0

Use contentType: "text/plain", .

var url = 'http://testejn.hospedagemdesites.ws/api/bairros/16';
$.ajax({
    type: 'GET',
    url: url,
    async: false,
    contentType: "text/plain",
    dataType: 'jsonp',
    success: function (data) {
        console.log(data[0]);
    }
});

jsFiddle: link

    
01.10.2015 / 16:34