Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created July 4, 2009 23:56
Show Gist options
  • Select an option

  • Save inklesspen/140772 to your computer and use it in GitHub Desktop.

Select an option

Save inklesspen/140772 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
</head>
<body>
Hey dudes. Here is the JSON console. This requires native JSON (though you could easily throw in the json2.js library to replace it) and the HTML5 Canvas element. I have only tested it on Firefox 3.5, but recent WebKit nightlies ought to work too.
<p>
<label for="url">URL: </label><input type="text" name="url" value="http://127.0.0.1:8000/1/" id="url"> <label for="request_method">Request Method: </label><input type="text" name="request_method" value="POST" id="request_method">
<br>
Json: <br>
<textarea name="json_val" id="json_val" rows="20" cols="80"></textarea><canvas id="okaylight" width="30" height="30"></canvas>
<br>
<input type="submit" name="go_time" value="Go Time" id="go_time">
Result: <br>
<textarea name="result" id="result" rows="20" cols="80"></textarea>
</p>
<script type="text/javascript" charset="utf-8">
var key_timeout_check = null;
var validate_json = function() {
var good = null;
var canvas = document.getElementById("okaylight");
var ctx = canvas.getContext("2d");
var possible_json = $("#json_val").val();
try {
JSON.parse(possible_json);
good = true;
} catch (e) {
good = false;
}
if (good) {
ctx.fillStyle = "green";
} else {
ctx.fillStyle = "red";
}
ctx.clearRect(0, 0, 30, 30);
ctx.fillRect(0, 0, 30, 30);
};
var reset_timeout = function() {
if (key_timeout_check != null) {
clearTimeout(key_timeout_check);
key_timeout_check = null;
}
key_timeout_check = setTimeout(validate_json, 1000);
};
$("#json_val").keypress(reset_timeout);
$("#go_time").click(function() {
$.ajax({data: {json: $("#json_val").val()}, dataType: "text", type: $("#request_method").val(), url: $("#url").val(), success: function(data) {$("#result").val(data);}});
return false;
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment