2016-09-28 68 views
0

所以我在views.py簡單的Hello World,AJAX Django的

def home(request): 
    return render_to_response('proj1/index.html', RequestContext(request, {'variable': 'world'})) 

這個功能,我想使用AJAX來顯示的 「Hello World」;

Ajax的功能,像這樣:

$.ajax({ 
url: "/proj1" 
type:"GET", 
dataType: "html", 
success: function(data){ 
    <h1>Hello {{data.variable}}, welcome to my AJAX WebSite</h1> 
}  
}); 

我如何實現的呢? 謝謝!

+0

如果你想爲什麼你使用'render_to_response'擺脫Ajax響應,你最好使用'HttpResponse'。 –

+0

我喜歡渲染比http .. :) –

+0

目前還不清楚你在問什麼。 –

回答

0

確保'url:「/ proj1」'指向調用該視圖的url。

本教程將解決你的疑惑:

https://godjango.com/18-basic-ajax/

+0

感謝Tut! :) –

+0

歡迎您! ;) –

相關問題