Created
July 10, 2016 14:25
-
-
Save arkenous/7f5b593d107f5dcd48faab4e22ad4df7 to your computer and use it in GitHub Desktop.
mac-debug-python3-cgi-web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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