jorgebastida / django-dajax

Easy to use library to create asynchronous presentation logic with django and dajaxice
http://dajaxproject.com/
BSD 3-Clause "New" or "Revised" License
346 stars 99 forks source link

jquery not working properly...takes exactly 2 arguments (1 given) #48

Closed arafiq closed 12 years ago

arafiq commented 12 years ago

Hey,

So when I use mootools, dojo or prototype I get no errors while using dajax( I currently use 0.5.2v dajaxice,0.9.2v dajax, 1.4.1 django ). I have followed the documentation for Dajaxice and Dajax to set the project. And like I mentioned before it works with the other JS frameworks just not jquery. I have also tested it with different versions of jquery and I get the same error. I get the following error:

ERROR:django.request:Internal Server Error: /dajaxice/projects.employeeSearch/ Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 111, in get_response response = callback(request, _callback_args, _callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 48, in view return self.dispatch(request, _args, _kwargs) File "/usr/local/lib/python2.7/dist-packages/dajaxice/views.py", line 52, in dispatch response = function.call(request, *_data) File "/usr/local/lib/python2.7/dist-packages/dajaxice/core/Dajaxice.py", line 18, in call return self.function(_args, **kwargs) TypeError: employeeSearch() takes exactly 2 arguments (1 given)

This is what I am doing in my template:

       {% load dajaxice_templatetags %}

        .
        .
        <script src="http://www.google.com/jsapi"></script>
        <script>    
         // Load Prototype
         //google.load("prototype", "1.6.0.3");
         google.load("jquery", "1.6.2");
        //google.load("mootools", "1.2.1");
        //google.load("dojo", "1.3.1");    

        function my_callback(data){
              alert(data+' received from server');
        }    
        </script>

        {% dajaxice_js_import %}

         <script type="text/javascript" charset="utf-8">
          var Dajax = {
               process: function(data)
                   {
                      $.each(data, function(i,elem){
             .
             .
         </script>

         {% block content  %}
          <form id="target" action="/resultsLC/" method="get">

         <input type="text" name="employeeid" id="employeeid" value="" placeholder=Employee   
     required onblur="Dajaxice.projects.employeeSearch(Dajax.process,{'employeeid':$('employeeid').value});">
        .
            .

ajax.py

from dajax.core import Dajax from dajaxice.decorators import dajaxice_register from projects import SearchForm @dajaxice_register def employeeSearch (request, employeeid): dajax = Dajax() result = SearchForm.search(emp) dajax.assign('#employeeid', 'value', str(result)) return dajax.json()

In my chrome browser console this is the error message I get. Dajaxice: Something went wrong. dajaxice.core.js:114

EXCEPTION: 'DAJAXICE_EXCEPTION',
default_settings: {'default_exception_callback': function(){ console.log('Dajaxice: Something went wrong.')}}

If you could illuminate what I am doing wrong I would really appreciate it.

Thanks

arafiq commented 12 years ago

I figured this out days ago. There was an issue with my use of selectors ( # ) while calling the dajax function from the template.

ghost commented 11 years ago

I have the same problem after upgrading to the latest versions of Django, Dajax and Dajaxice. I don't understand your solution.

arafiq commented 11 years ago

<input type="text" name="employeeid" id="employeeid" value="" placeholder=Employee onblur="Dajaxice.projects.employeeSearch(Dajax.process,{'employeeid':$('employeeid').val()});

On the above line notice: {'employeeid':$( 'employeeid' ).val()}); [ No # employeeid]

it should be: {'employeeid':$(' #employeeid ').val()});

ghost commented 11 years ago

Ok. Thank you. I don't know why, but I just tried the same code without modification and works. Sorry for waste your time.