Created
March 28, 2016 10:55
-
-
Save jainmickey/8765e36cd9c8c38735ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
views.py | |
``` | |
from django.shortcuts import render | |
from django.http import JSONResponse | |
from server import list_connections, get_target, send_target_commands | |
def get_output(request): | |
cmd = request.GET.get('command') | |
msg = 'Command not recognized' | |
if cmd == 'list': | |
msg = list_connections() | |
elif 'select' in cmd: | |
conn == get_target(cmd) | |
if conn: | |
msg = send_target_connections(cmd) | |
return JSONResponse({'message': msg}) | |
urls.py | |
``` | |
url(r'get_output/$', views.get_output, name='get_output') | |
``` | |
personal/home.html | |
``` | |
$("send_button_id").click(function(){get_output();}); | |
function get_output() { | |
$.ajax({ | |
url: "/get_output", | |
data: {"command": "list"}, | |
success: function(response) { | |
alert(response); | |
}, | |
error: function(xhr) { | |
//Do Something to handle error | |
} | |
}); | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment