Jameson
Jameson

Reputation: 968

Using jsonp in jquery seems to always fail

I get 'error' almost no matter what I'm trying to load in using the dataType 'jsonp' in the ajax method of jquery, however using just 'json' works fine for the same json content. I need to use jsonp because I'm calling an external API to work with.

Js method:

$.ajax({
            url: 'test3.json',
            type: 'GET',
            dataType: 'json',
            data: {
                action: 'APICALL',
                ID: '59'
            },
            success: function(data, textStatus, xhr) {
             console.log('success');
            },
            error: function(data, textStatus, xhr) {
             console.log('error: '+textStatus);
             console.log(data);
            },
            complete: function(data, textStatus, xhr) {
             console.log('complete');
            }

        });

})

test3.json file:

{"symbol": "IBM", "price": "91.42"}

Upvotes: 0

Views: 183

Answers (1)

SLaks
SLaks

Reputation: 888187

That's not JSONP.

You need to write a JSONP endpoint that honors the callback parameter.

Upvotes: 5

Related Questions