[英]Dajax example doesnt work
因此,我試圖擺脫Dajaxice對Django的影響。 在我使用Dajaxice之前,一切都很好,但是我嘗試Dajax時遇到了麻煩。
我創建了一個新項目,並在其中包含一個示例應用程序。 因此,然后我制作了一個按鈕-模板中的按鈕1,該模板使用ajax.py中的函數,此方法工作正常。 但是,按鈕2無效,它使用了ajax.py中的第二個功能。 我在下面粘貼了index.html和ajax.py代碼。 我如何才能使Button 2正常工作,並使它按我想要的方式工作。
的index.html
{% load dajaxice_templatetags %}
{% dajaxice_js_import %}
<input type="button" value="Button 1" onclick="Dajaxice.example.sayhello(my_js_callback);"/>
<br>
<input type="text" id="text"/>
<input type="button" value="Button 2" onclick="Dajaxice.example.saytext(my_js_callback, {'text':$('#text').val()});"/>
<script type="text/javascript">
function my_js_callback(data){
alert(data.message);
}
</script>
ajax.py
from django.utils import simplejson
from dajaxice.decorators import dajaxice_register
@dajaxice_register
def sayhello(request):
return simplejson.dumps({'message':'Hello World!'})
@dajaxice_register
def saytext(request, text):
return simplejson.dumps({'message':'%s' % text})
在過去的幾年中,這已經被多次提及。 Dajaxice項目不是一個好主意,您應該只使用JQuery和AJAX將數據發布/接收到django視圖。
作者在他的Github頁面上說過; “如今使用這個項目是一個壞主意。”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.