I'm trying to have Django to run a function when I tell it based off a JavaScript button. How do I accomplish this? Where do I write the Django function?
JavaScript in main.html:
function mainFunction(){
alert("Beginning API Main Function");
$.ajax({
type: 'POST',
url: 'livestream/postdata/',
success: function(){alert('DONE!');},
error:function(){alert('ERROR!');},
});
alert("ENDING API MAIN FUNCTION");
}
Urls.py:
url(r'^postdata$', 'livestream.views.postdata', name='postdata')
Views.py:
def postdata(request):
r = ...api... (I know that the api works)
print(r.text)
When I run the function 'mainFunction()' I get the two alerts and then another that says 'ERROR'. Why is this?
url: '/livestream/postdata/',
(notice that first/
?)