Page 1 of 2

displaying returned data from json vs jsonp

Posted: Tue Aug 23, 2011 11:13 pm
by mfratto

what's the story with json vs jsonp? I am trying to use some json feeds from broadbandmap.gov http://www.broadbandmap.gov/broadband...) and when I build the data and test the REST service as json, I can see the fields and I can map them. Using jsonp, the service returns an error.

However, I can't see any results in the app when I test it.


displaying returned data from json vs jsonp

Posted: Tue Aug 23, 2011 11:26 pm
by maxkatz

It's a default security feature. When using json, you can only invoke services from the same domain from which the page was loaded. For example, if the page was loaded from mydomain.com, you can only invoke services from mydomain.com. It works inside Tiggr as it's not coming from a web page.

jsonp is a (standard) workaround (http://en.wikipedia.org/wiki/JSONP), to make it possible to invoke services from a different domain. So, when the page is loaded from gotiggr.com, you can invoke services from broadbandmap.com.


displaying returned data from json vs jsonp

Posted: Tue Aug 23, 2011 11:34 pm
by mfratto

Max, thanks. So the problem is that when I set data type to jsonp, the service returns "406, Not Acceptable."

I am guessing that jsonp as to be supported at the service, yah?


displaying returned data from json vs jsonp

Posted: Tue Aug 23, 2011 11:39 pm
by maxkatz

Sorry, I got it wrong. Tiggr is not sending the right header information when using jsonp. If you add this request param: accept=application/json -- service Test works fine with jsonp.


displaying returned data from json vs jsonp

Posted: Tue Aug 23, 2011 11:53 pm
by mfratto

OK, that works.

I am still not getting data displayed on the screen. I mapped the array to the grid and then the two fields to display labels. I am not seeing it populate.


displaying returned data from json vs jsonp

Posted: Tue Aug 23, 2011 11:56 pm
by maxkatz

Please share the project with a href="mailto:support@gotiggr.com" rel="nofollow"support@gotiggr.com/a, I'll take a look at the service/mappings. Here is how to share: http://help.gotiggr.com/documentation...


displaying returned data from json vs jsonp

Posted: Wed Aug 24, 2011 12:03 am
by mfratto

done. :)


displaying returned data from json vs jsonp

Posted: Wed Aug 24, 2011 12:35 am
by maxkatz

Fixed. We set format=jsonp. Every service out there works in slightly different way.


displaying returned data from json vs jsonp

Posted: Wed Aug 24, 2011 12:44 am
by mfratto

huh. Thanks.

Just so I know in the future, it's a matter of finding the right combination of setting the format as a header, datatype, and argument.

I was reading the broadband.gov API, and they ask for a call back for jsonp. I take it that tiggr automatically adds the callback?


displaying returned data from json vs jsonp

Posted: Wed Aug 24, 2011 12:46 am
by maxkatz

Yes, it's automatically added by jQuery Mobile. But if needed, you can specify the callback function yourself.