JSONP - “Uncaught SyntaxError: Unexpected token”

302 Views Asked by At

I am making a JSONP AJAX request and receiving an error:

Uncaught SyntaxError: Unexpected token

What am I doing wrong in my code?

$.ajax({
    url: 'http://api.server32.trustklik.com/apiv1/website/reviews?client_id=098jdsahq67tgysfrtf1babza8y97z8h&client_secret=nfijsadhf7843ryuhfy34287yhrfuihf872h4831qzaqwd32qcwqefcmowqkoeqwkfjieuqhixefhuiwrehfo&domain_name=www.uatourtesting.rajapremi.co.id',
    dataType: 'JSONP',
    jsonpCallback: 'callback',
    type: 'GET',
    success: function (data) {
        console.log(data);
    }
});

This is my fiddle: http://jsfiddle.net/repjt/590/

2

There are 2 best solutions below

0
Bhupendra Piprava On

Hi your response data is not properly formatted.

I mean it is not valid json data.

Copy your response data and validate on JSON Validator

nothing wrong with your request. "avatar_url" having escape char

your response

 "avatar_url": "http:// sandbox.trustklik.com/media/images/standard/avatar/32E1209610FBED38D1E6FE4C9266BCCF8315DA37.png",

change it to

  "avatar_url": "http://// sandbox.trustklik.com/media/images/standard/avatar/32E1209610FBED38D1E6FE4C9266BCCF8315DA37.png",

instead of having http:// put http:////.

1
vikramaditya pedamallu On

No problem with the URL, only problem with the outcome data which is not in the standard format of JSON : {["Attribute":"Value"]} eigther its single or an array instead of using own logic to format the data at the server end use built in functions for JSON from data set or source respective to Technology you used will help you