Я делаю long polling
в Django
(1.11). Но я не понимаю, почему JsonResponse
возвращает неопределенные значения ?
Аякс
$('.txt_link > a').on('click', function() {
$.ajax({
type: 'GET',
url: '',
success: function(data){
console.log(data.title) //undefined
}
})
})
вид
class ProviderCreateView(CreateView):
form_class = ProviderForm
template_name = 'provider_create.html'
def form_valid(self, form):
...
def get_context_data(self, **kwargs):
ctx = super(ProviderCreateView, self).get_context_data(**kwargs)
ctx['organizations'] = Organization.objects.filter(user=self.request.user)
last_organization = Organization.objects.filter(user=self.request.user).first()
if self.request.is_ajax():
while True:
curr_organization = Organization.objects.filter(user=self.request.user).first()
if last_organization != curr_organization:
template_ajax = render_to_string(
template_name='provider_create.html',
context=ctx
)
return JsonResponse({
'success': True,
'template': template_ajax,
'pk': curr_organization.pk,
'title': curr_organization.title
})
time.sleep(2)
return ctx