Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using JSONP breaks parsing of return data #27

Closed
antonfh opened this issue May 30, 2014 · 3 comments
Closed

Using JSONP breaks parsing of return data #27

antonfh opened this issue May 30, 2014 · 3 comments

Comments

@antonfh
Copy link

antonfh commented May 30, 2014

Good day,

Maybe I missed it in the notes or other questions, but I can not see any mention of the following. To fix CORS, I am using JSONP, but now I am getting errors on the returned data :

Timestamp: 2014/05/30, 14:45:45
Error: SyntaxError: missing ; before statement
Source File: http://www.site.cc/rand?callback=jQuery20302740955555920611_1401453890633&_=1401453890657
Line: 1, Column: 8
Source Code:
{"total":62}

basically indicating that between total and 62 (at the colon) there is a missing ; before statement ?

Worked fine on JSON when running both data and freeboard on same server/site

Thanks for the time and effort.

@jheising
Copy link
Contributor

I'm getting a 404/notfound error on that link. Can you send me a valid one? Thanks.

@antonfh
Copy link
Author

antonfh commented May 30, 2014

Hi sorry, yes that is on a local test (not public facing/access) basically its only an api that returns the data element (json_encoded) as {"total":"40"} , or another call returns something like {"id":"1","name":"my name","total":"1") ..... which results in same error indicating that the very first : is where a missing ; before statement must be .... how must a custom plugin/ data source be defined (I have one obviously calling these apis) which used types JSON but now I define JSONP (so not sure if a datasource which worked/works with JSON can simply just change type to JSONP (or is there some changes that must be made to handle JSONP ?

Thanks

@jheising
Copy link
Contributor

Oh, I think the problem is that your JSONP file isn't really JSONP. http://en.wikipedia.org/wiki/JSONP. JSONP is actually a script file that must be formatted like javascript and calls back the function passed in the URL. So for that example above, the file would need to look like:

jQuery20302740955555920611_1401453890633({
"total": 62
});

The main thing is that the function name changes randomly so you need to make sure your API endpoint is taking this into account when it creates the JSONP file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants