Gregorius Airlangga Gregorius Airlangga - 1 year ago 98
jQuery Question

Uncaught SyntaxError: Unexpected token : , when i access json api

I'm trying to get data from:

I'm using the jQuery
method and the code is written in my

function getAPI() {
url: '',
dataType: 'jsonp',
crossDomain: true,
jsonp: false,
success: function(data) { console.log(data); }

When I try it in the Chrome console, there is a message

Uncaught Syntax Error:Unexpected token:

I am very confused about what the problem is, can anyone help me?

Answer Source

The content being returned is json, not jsonp as you specified in your dataType. Also, by setting jsonp to false, you're preventing a jsonp querystring from being appended to the URL by jquery, which is likely why the API you're using is returning json and not jsonp. I would try taking out the jsonp: false parameter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download