I have a js code, which on the on click event sends a POST request to /productionFloor/wip/ I have a view that receives those requests (also printing to the console all the arguments that were passed correctly). I'm trying to render a template with the data received from the POST request, but django won't render the view.
Here is my view:
def wip_view(request):
if request.method == "POST":
print(request.POST['id'])
print(request.POST['process'])
return render(request, 'wip.html', {'nbar': 'production_floor'})
Here is the js:
$(".clickable-schedule-row").dblclick(function() {
id=$(this).children('td')[6].innerHTML;
process=$(this).children('td')[7].innerHTML;
$.post("/productionFloor/wip/", {'csrfmiddlewaretoken': $("[name=csrfmiddlewaretoken]").val(),
'id': id, 'process': process});
});
as I mentioned, the server gets the request correctly and prints the right data, but it won't change the page on the browser.
Basically you are using the ajax call from jQuery. Django return the response in json/string format. Inside the success method you will have to make changes to reflect it in the HTML pages.
$.ajax({
type: "GET",
url: '/productionFloor/wip/',
data:"{'csrfmiddlewaretoken': $("[name=csrfmiddlewaretoken]").val(),
'id': id, 'process': process}",
success: function(response) {
// inside this function you have to bind html content using javascript, because ajax call will not render complete page.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With