2

My state legislature website offers a restful api.

What is the correct javascript / jquery code to fetch the value of kslegislature.org/li/api/v5/rev-1/bill_listing/ into a variable?

I can not seem to construct a working .getJSON request to pull the data.

Ultimately I want to be able to work with values like

var kslegBills = RETURNED DATA;
console.log(kslegbills.content[1].BILLNO)

complete API guide available here: http://www.google.com/url?sa=D&q=http://kslegislature.org/kliss_restian_interface_guide_v5.odt

A gentle shove in the right direction would be greatly appreciated.

jQuery.getJSON("http://www.kslegislature.org/li/api/v5/rev-1/bill_listing/&callback=?", [], function(data, textStatus) { var kslegbills = data; alert(textStatus); } )

UPDATE:

Thanks to @JackWinks I was able to get a working request through a PHP wrapper. Working model at http://kansasgrassroots.com/files/kslegbills/

It works in chrome, but not firefox or safari. I suspect it is because of the large size of the request that FF and Safari are timing out before data is returned.

Jake Lowen
  • 899
  • 1
  • 11
  • 21
  • Jake, it's generally useful on this site if you can post some code you have tried. – griegs Oct 06 '11 at 05:02
  • Please show us the code you've written so far. – Jordan Running Oct 06 '11 at 05:05
  • Thanks griegs - here is the closest I've gotten... This at least returns the data, but I've not figured out how to pass the data in to a variable.. `jQuery.getJSON("http://www.kslegislature.org/li/api/v5/rev-1/bill_listing/&callback=?", [], function(data, textStatus) { var kslegbills = data; alert(textStatus); } )` – Jake Lowen Oct 06 '11 at 05:06
  • Be gentle. I'm such a noob. Trying not to get discouraged. Be verbose in your explanation please so I can learn. – Jake Lowen Oct 06 '11 at 05:09
  • and what does the alert give you? – griegs Oct 06 '11 at 05:10
  • I can't see that the alert ever triggers. The only notice I get in the console (firebug) is "invalid label 'content [" Which comes from the data reported back from the API – Jake Lowen Oct 06 '11 at 05:13
  • if you are not passing data no need for `[]` in the place of second argument just try with `jQuery.getJSON("http://www.kslegislature.org/li/api/v5/rev-1/bill_listing/&callback=?", function(data, textStatus) { var kslegbills = data; ale` – Rafay Oct 06 '11 at 05:16
  • $.getJSON("http://www.kslegislature.org/li/api/v5/rev-1/bill_listing/?jsoncallback=?", function (data) { alert(data); }) is not working for me so not sure that's the issue @3nigma – griegs Oct 06 '11 at 05:20
  • 1
    I don't think that API is set up to be cross-domain accessible. From what I see in the spec, there is no mention of jsonp, and when requesting the domain with callback=?, I get a 503 error. If you want, you can read up on the same-origin policy: http://en.wikipedia.org/wiki/Same_origin_policy There is a general workaround, where you proxy the request through your server: http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html – JackWink Oct 06 '11 at 05:20
  • @griegs yup i though just in case... – Rafay Oct 06 '11 at 05:26
  • Strange.. It seems back up now. No longer returning 503 - now 200. – Jake Lowen Oct 06 '11 at 05:39

1 Answers1

0

I didn't find any key word about 'jsonp' in that document, so does that api support jsonp?

lostyzd
  • 4,515
  • 3
  • 19
  • 33