XHR status returns 0 in ajax call to a django generic view -
this totally weird because don't know why returning error when replicated same code 1 section another, change title of generic views (updateview) , never execute function return form edit single customer, that's code:
urls
from django.conf.urls import patterns, include, url django.contrib.staticfiles.urls import staticfiles_urlpatterns . import views . import forms . import invoice urlpatterns = patterns('', url(r'^pedidos/',views.pedidoslistview.as_view(),name="pedidos_list"), url(r'^pedidos/add',views.add_pedido, name="pedido_add"), url(r'^pedidos/edit/(?p<pedido_id>\d+)',views.edit_pedido, name="pedido_edit"), url(r'^pedidos/delete/(?p<pedido_id>\d+)',views.delete_pedido, name="pedido_delete"), url(r'^pedido/(?p<pk>\d+)',forms.detailpedido.as_view(), name="pedido_detail"), url(r'^pedido-pdf/(?p<pk>\d+)',invoice.detalle_pedido_pdf, name="pedido_detail_pdf"), url(r'^clientes/',views.clienteslistview.as_view(),name="clientes_list"), url(r'^clientes/edit/(?p<pk>\d+)$',forms.clienteupdateview.as_view(), name="clientes_edit"), url(r'^empleados/edit/(?p<pk>\d+)$',forms.empleadoupdateview.as_view(),name="edit"), url(r'^empleados/',views.empleadolistview.as_view(),name="list"), )
forms
class clienteupdateview(updateview): form_class = clientemodelform model = cliente template_name = 'ventas/form.html' def get(self, request, **kwargs): self.object = cliente.objects.get(pk=self.kwargs['pk']) form_class = self.get_form_class() form = self.get_form(form_class) context = self.get_context_data(object=self.object, form=form) return self.render_to_response(context) def form_valid(self, form): self.object = form.save(commit=false) self.object.save() return httpresponseredirect('ventas/clientes_list.html') def form_invalid(self,form): if self.request.is_ajax(): return httpresponsebadrequest(json.dumps(form.errors), mimetype="application/json")
javascript
$(".edit").click(function(ev){ ev.preventdefault(); var url = $(this).data('form'); $.ajax({ url: url, success: function(data, status){ $('body').append($('<div id="mymodal" class="modal hide fade">' + data + '</div>').modal()); $("#mymodal").find(".datepicker" ).datepicker({ dateformat: "dd/mm/yy" }); }, error: function (xhr, ajaxoptions, thrownerror) { console.log(xhr.status); console.log(xhr.responsetext); console.log(thrownerror); } }) return false; // prevent click propagation });
html
<button data-form="{% url 'ventas:clientes_edit' c.id %}" class="edit btn btn-mini btn-info">
if in ajax url change value 'ventas/empleados/edit/someid' (the same replicated clienteupdateview
, can retrieve form employee edit can't same customer, i'm missing i'm not able notice? it's driving nuts! ideas?
regards!
Comments
Post a Comment