Skip to content

Instantly share code, notes, and snippets.

@jainmickey
Created March 28, 2016 10:55
Show Gist options
  • Save jainmickey/8765e36cd9c8c38735ae to your computer and use it in GitHub Desktop.
Save jainmickey/8765e36cd9c8c38735ae to your computer and use it in GitHub Desktop.
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