Gregorius Airlangga Gregorius Airlangga - 1 month ago 15
jQuery Question

Uncaught SyntaxError: Unexpected token : , when i access tickets.com json api

I'm trying to get data from:

http://api.master18.tiket.com/search/autocomplete/hotel?q=mah&token=90d2fad44172390b11527557e6250e50&secretkey=83e2f0484edbd2ad6fc9888c1e30ea44&output=json


I'm using the jQuery
$.ajax
method and the code is written in my
index.html
file:

function getAPI() {
jQuery.ajax({
url: 'http://api.master18.tiket.com/search/autocomplete/hotel?q=mah&token=90d2fad44172390b11527557e6250e50&secretkey=83e2f0484edbd2ad6fc9888c1e30ea44&output=json',
type:"get",
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

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.

Comments