[Answer]-Dajax not working

0👍

Apparently javascript function names with underscores(‘_’) don’t work when using functions like onclick.It’s better to use functions like somefunction() instead of some_function() to make Dajax work.

1👍

django-dajax and django-dajaxice

Should I use django-dajax or django-dajaxice?

In a word, No. I created these projects 4 years ago as a cool tool in
order to solve one specific problems I had at that time.

These days using these projects is a bad idea.
(…)
If you want to use this project, you are probably wrong. You should
stop couplig your interface with your backend or… in the long term
it will explode in your face.

jorgebastida/django-dajax

👤Trix

0👍

The following is an example to make Helloworld using dajax

models.py:

 from django.db import models
 from dajax.core import Dajax
 from dajaxice.decorators import dajaxice_register
 @dajaxice_register
 def say_hello(request,value):
    dajax = Dajax()
    dajax.alert(value)
    return dajax.json()

urls.py:

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'server.views.index', name='index'),

where “server” in server.views.index is the application name inside your project

in index.html file you have to use a jquery function to call this dajax request as following
index.html:

 <html>
    <script>
      function print_helloworld(){
                var value = Dajaxice.server.models.say_hello(Dajax.process,{'value':'Hello World!'});
            }
    </script>
    <body>
       <button id='mybtn' class='btn btn-primary' onclick='print_helloworld()'>Hello World</button>
    </body>
 </html>

if you need to access the index file from public ip you have to add the {% csrf_token %} token before button

👤0x3bfc

Leave a comment