Im trying to send my serialized form data to django where it will should be stored in "mylist" as a list "[video, audio]". views.py return 0 everytime no matter what boxes I check on my form.
html form
<form id="myform" method="POST">
<input type="checkbox" name="list" value="audio"/> Audio<br />
<input type="checkbox" name="list" value="video"/> Video<br />
<input type="submit" value="Get Custom Library!" />
</form>
jquery ajax
<script language="JavaScript">
$(document).ready(function() {
$("#myform").submit(function() {
$.ajax({
type: "POST",
url: 'django/builder/buildit',
data: $(this).serialize(),
success: function(response){
alert(response);
}
});
return false;
});
});
</script>
views.py
from django.http import HttpResponse
def main(request):
mylist = request.POST.getlist('list')
message = 0
for item in mylist:
if item == 'video':
message = 'vid'
elif item == 'audio':
message = 'aud'
return HttpResponse(message)