I am trying to submit a form asynchronously using a form
tag, <input type='submit' method=get>
, and jQuery.
When I click the submit button I am getting the following error in my terminal traceback:
[24/Mar/2016 03:55:14] "GET /? HTTP/1.1" 200 1270
[24/Mar/2016 03:55:14] "GET /submitted/1458791714827 HTTP/1.1" 302 0
- Broken pipe from ('127.0.0.1', 33187)
Here is my HTML...
<body>
<h1>API: Disney</h1>
<form method="get">
<input type='submit' value='CLICK ME VIEW ALL TIMESTAMPS BETWEEN NOW AND 5 MINUTES AGO!'></input>
</form>
</body>
Here is my jQuery...
$(document).ready(function(){
$('form').submit(function(){
var submittime = new Date().getTime()
$.ajax({
url: 'submitted/' + submittime,
});
});
})
Here is my View...
class SubmitValue(View):
def get(self, request, currdate):
val = random.randrange(1,100)
date = int(currdate)
Data.objects.create(value=val, curr_time=date)
return redirect('/')
Here is my apps urls.py file...
url(r'^submitted/(?P<currdate>\d+)$', SubmitValue.as_view()),
Here is my Models...
from django.db import models
class Data(models.Model):
value = models.IntegerField()
curr_time = models.BigIntegerField()