1

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 ? :(

zzlalani
  • 22,960
  • 16
  • 44
  • 73
  • Your data is JSON, not JSONP. – Quentin Jun 11 '15 at 11:54
  • @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 Jun 11 '15 at 12:04
  • 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 Jun 11 '15 at 12:08
  • @Quentin isn't it a valid `JSONP`? https://sergedenimes.com/wc-api/v2?_jsonp=JSON_CALLBACK – zzlalani Jun 11 '15 at 12:34
  • with this url it says `GET http://pwoo.dev/wc-api/v2?_jsonp=angular.callbacks._0?callback=JSON_CALLBACK ` – zzlalani Jun 11 '15 at 12:35

1 Answers1

0

The jsonp content should be between a callback function like:

JSON_CALLBACK({"data":{"A":123,"B":true}})