Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

I'm trying to fetch data from wooCommerce api in an angularjs application using jsonp method

$http.jsonp('http://pwoo.dev/wc-api/v2?callback=JSON_CALLBACK')
.success(function ( data, status, headers, config ) {
    console.log(data, status, headers, config);
})
.error(function ( data, status, headers, config ) {
    console.log("Error", data, status, headers, config);
});

and in return it gives me this error in console

Uncaught SyntaxError: Unexpected token :

and breaks the code in error block

http://jsfiddle.net/zzlalani/5Lj46p69/

here is the live link from same type of api I used in fiddle above

https://sergedenimes.com/wc-api/v2

I have validated the json online and its correct and valid in format, you check it here in fiddle's console in the following link

https://jsfiddle.net/zzlalani/ru6kozxn/1/

Update:

Ok its not working for jQuery.ajax as well check the fiddle below where I have used simple jquery's $.ajax method with dataType: "jsonp"

https://jsfiddle.net/zzlalani/zvreh2xp/2/

I don't understand where is the issue because in my above angular example a simple test.json with data

{
    "name": "zeeshan Lalani"
}

throws same error. What m'I missing here? How people in this world use JSONP examples ? :(

share|improve this question

marked as duplicate by Quentin 14 hours ago

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Your data is JSON, not JSONP. –  Quentin 14 hours ago
    
@Quentin I cannot make changes to api server, what changes should I make to access data as jsonp because with normal get call i get those cross domain issues. –  zzlalani 14 hours ago
    
You need the cooperation of the server if you want to get around the security systems that block cross origin requests. Use a different server if you don't control that one. –  Quentin 14 hours ago
    
ok thanks @Quentin –  zzlalani 14 hours ago
    
@Quentin isn't it a valid JSONP? sergedenimes.com/wc-api/v2?_jsonp=JSON_CALLBACK –  zzlalani 13 hours ago

1 Answer 1

The jsonp content should be between a callback function like:

JSON_CALLBACK({"data":{"A":123,"B":true}})
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.