python - Refresh Div elements withoud reload Page using Ajax and DJango -


i read many posts in site refresh elements without reload page, can't fix problem. have view called 'operation' , need refresh these page each 5 seconds. then, created other view called 'refresh' update data.

but returns error 404 when open page. how can fix problem? 'post /operation/refresh http/1.1 404 2317'

views.py

def main(request):     dp_col = datadisplay.objects.all()     #print(dp_col[0].name)     reg = registers.objects.latest('pk')     context = {         'dp_col': dp_col,         'reg':reg     }     return render(request,'operation.html',context)  def refresh(request):      if request.is_ajax():         reg = registers.objects.latest('pk')         print(reg)         #return render(request,'operation.html',{'reg':reg})         return httpresponse({'reg':reg}) 

operation.js

function refresh_function(){     $.ajax({         type: 'post',         url: 'refresh',         success: function(data){             //atualizar os dados da página             alert(data);         }     }) }  $(document).ready(function(){     $('#sp_pumpspeed').slider({         formatter: function(value){             return 'current value: ' + value;     }}),      setinterval(refresh_function,1000);   }); 

without knowing more i'm guessing you're receiving 404 since have hard-coded url "refresh" in $.ajax() call not valid.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -