MickJagger
MickJagger

Reputation: 27

Dajax example doesnt work

So I'm trying to get the hang of Dajaxice for Django. Everything was fine till I used Dajaxice, but just I tried Dajax I gat trouble.

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: 246

Answers (1)

Chris Hawkes
Chris Hawkes

Reputation: 12410

this has been said multiple times over the last few years. The Dajaxice project is a bad idea and you should just use JQuery and AJAX instead to post/receive data to your django view.

The author has stated on his Github page; "These days using this project is a bad idea."

Upvotes: 1

Related Questions