Simar
Simar

Reputation: 2505

Dajax - function in ajax.py not working

So I'm trying to get the hang of Dajax for Django. Everything was fine till I made a second function in ajax.py.

I made a new project and inside it an example app. So then I made a button - Button 1 in a template which uses a function in ajax.py, this worked fine. Button 2 did not work though, which uses the second function in ajax.py. I have pasted the index.html and ajax.py code below. How can I get the Button 2 to work, and make it do what I want it to do.

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})

Upvotes: 1

Views: 136

Answers (1)

Simar
Simar

Reputation: 2505

So, after spending hours searching online, I finally read somewhere that "it would save you from a whole lot of pain if you just used Python 2.7". And that's what I did, I uninstalled Python 3.3 and installed 2.7 and it worked!

Upvotes: 1

Related Questions