Skip to content

Instantly share code, notes, and snippets.

@arkenous
Created July 10, 2016 14:25
Show Gist options
  • Save arkenous/7f5b593d107f5dcd48faab4e22ad4df7 to your computer and use it in GitHub Desktop.
Save arkenous/7f5b593d107f5dcd48faab4e22ad4df7 to your computer and use it in GitHub Desktop.
mac-debug-python3-cgi-web
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Test page</title>
</head>
<body>
<h2>It works!</h2>
<h4>CGI Output: <span id="cgi_output"></span></h4>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="sample.js"></script>
</body>
</html>
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
import json
print("Content-type: application/json")
print("\n\n")
today_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")
response = {'result': today_time}
print(json.JSONEncoder().encode(response))
print("\n")
$(window).load(init());
function init() {
test();
}
function test() {
$.ajax({
type: 'POST',
url: 'sample.cgi',
contentType: 'application/json',
success: function(data) {
$('#cgi_output').empty();
var result = data.result;
$('#cgi_output').text(result);
}
});
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment