Realtime Congress Example

by dandiebolt

HTML

<h4><center>Some JSON testing</center></h4>

url to web service:
<input id="js_test_url" type="text" style="width:80%" name="url" value="foo" />
<BR>
<input id="js_testbtn" type="button" style="width:90px;" onclick="Do_JSON_Test();" name="Name" value="Test Again" />

JavaScript

var _basepath = "http://api.realtimecongress.org/api/v1/amendments.json";
var _mykey = "?apikey=c388626ebddc40b9ad69d3972f344ac8";

function show_vars( data, pre ) {
    jQuery.each(data, function(key, val) {
        var __type = typeof(val);
        alert( pre + ' item: ' + key + '=' + val + '  type: ' + __type );
        if( __type == "object" || __type == "array" ) {]
            show_vars( val, key + ' =>' );
        }
    });
}

function Do_JSON_Test() {
    // set up the URL from the text input and add the callback arg
    var __url = jQuery('#js_test_url').val() + '&callback=?';
    //alert( 'About to call this url: \n' + __url );

    // go make the request
    jQuery.getJSON( __url, function(data) {
        alert( 'JSON data callback.' );
        show_vars( data, "" );
    });
}

// just want to load this now that the control is in place
jQuery('#js_test_url').val( _basepath + _mykey );