0

I am trying to access an API from bar.com from my site foo.com. Bar.com does NOT allow CORS, and I don't know if they officially support JSONP.

Can I still access the API via JSONP (using jQuery) or does the site explicitly need to support it?

Note, this is my AJAX request:

 $.ajax({ url: 'https://api.example.com', jsonp: 'callback', dataType: 'jsonp', data: { 'command' : 'abc', 'partnerName' : 'def', 'partnerPassword' : 'ghi', 'partnerUserID' : 'jkl', 'partnerUserSecret' : 'mnop' }, error: function (response) { console.log(response); return false; }, success: function (response) { console.log(response); return false; } }); }, 

From Chrome I get:

Uncaught SyntaxError: Unexpected token : 
1
  • 3
    The site needs to support it for it to work. Commented Jan 9, 2015 at 4:42

1 Answer 1

2

It's because what JSONP does is try to evaluate the code that comes from the API endpoint.

If the result of the call is, let's say

{"result": "OK"} 

then, to make JSONP work, the server had to respond it in that way:

callback({"result": "OK"}) 

as oyu defined a property jsonp as callback in your ajax call.

Sign up to request clarification or add additional context in comments.

2 Comments

Hmmm...I think the real issue is that the API doesn't support JSONP
@JustinCloud: yes, that's the point :) and my answer is an explanation why you need this support :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.