2
I have an array with a data dictionary in my Session and would like to remove according to the row the user is going to click on a table where these values are displayed.
My view:
def deletar_servico_ou_item_selecionado(request):
if request.is_ajax:
linhaClicada = request.POST.get('item')
lista = request.session['ord-serv']
del lista[linhaClicada - 1]
request.session['ord-serv'] = lista
return HttpResponse("/")
My JS:
var linhaClicada = $(this).parent().index();
$.ajax({
url: "/atendimento/deletar-servico-ou-item-selecionado/",
type: "POST",
data: {item: linhaClicada},
success: function(response) {
console.log("Success");
},
error: function(response) {
console.log("Error");
}
});
It seems my value doesn’t reach Django and I don’t know if I should use the type: "DELETE"
in that case.
Thank you for your answer, but my problem is
linhaClicada
does not reach AJAX.– Rodrigo Boniatti
Place a dataType: "json", below its date: {item: Clicate}. Also check that when calling ajax, still in the script, there is some value for binary
– Puam Dias
You should also look at your log console to see if there is an error in the script and if the view is being called correctly. You can debug what is coming in your post with pdb. import pdb; pdb.set_trace() https://mike.tig.as/blog/2010/09/14/pdb/
– Puam Dias
And put your dictionary in quotes. date: {"item": lineClicate}, :)
– Puam Dias
The following message is coming:
list indices must be integers, not NoneType
, but my lineClicate has a value.– Rodrigo Boniatti
In your view, try to get the data with: data = request.POST['data']. You have to see what’s coming in your view and how it’s coming in. You must be sending the information to the view but not getting it right.
– Puam Dias
That’s probably it, now you’re showing the following error:
MultiValueDictKeyError at /atendimento/deletar-servico-ou-item-selecionado/
"'item'"
– Rodrigo Boniatti
Let’s go continue this discussion in chat.
– Puam Dias