2016-03-29 26 views
-1

çalışmıyor, fonksiyon lütfen benim js kodu ve html bkz ı kontrol çağrıldığını, konsolDjango Ajax benim veri html plaka üzerinde değil işlenir Neden

<!-- HTML --> 
<div class="model" type="x-tmpl-mustache"><h1>{{model}}</h1> </div> 


// JavaScript 
$(document).ready(function(){ 
    $.get("/portfolio/model", function(data){ 
     console.log(data 
    $('div.model').html(data); 
}); 


# Python view 
class Return_portfolio(LoginRequiredMixin, View): 
    template_name = "dashboard.html" 

    def get(self,request): 
     user = request.user 
     model = Portfolio() 
     model_id = model.recommended_portfolio(request, user) 
     print(model_id) 
     if request.is_ajax(): 
      return JsonResponse({'model':model_id}) 

     return render(request, 'dashboard.html',{'portfolio_view':True}) 

    def post(self,request): 
     return HttpResponseNotAllowed(['GET']) 

cevap

0

bu deneyin hiçbir hataları verir:

$(document).ready(function(){ 
    $.get("/portfolio/model", function(data){ 
     console.log(data); 
     $('div .model').html(data); 
}); 

Konsol.log dosyanızda bir sözdizimi hatası oluştu. Ayrıca, ben jQuery eleman id değiştirdi.