The-WebOps-Club / fest-api

An API implementation for Saarang Shaastra like fests, including ERP and Mainsite and Mobile interface
12 stars 11 forks source link

Small problem running dajaxice #101

Closed akshayutture closed 10 years ago

akshayutture commented 10 years ago

I understood Dajaxice but the following example is not running on fest-api. Below are the changes I made to fest-api to try making it work. . The page opens. Other javascript functions work, but the one with dajaxice does not. (Online troubleshooting fr this problem has not helped)

  1. views.py (portals/events)

def portal_main2( request ): return render_to_response('portals/events/events2.html', locals(), context_instance = global_context(request))

  1. ajax.py is

from django.utils import simplejson from dajaxice.decorators import dajaxice_register

@dajaxice_register def args_example(request, text): return simplejson.dumps({'message':'Your message is %s!' % text})

  1. events2.html

{% extends 'base/base.html' %} {% load check_access %}

{% block content %}

{% load dajaxice_templatetags %}

{% dajaxice_js_import %} {% csrf_token %} sssa

{% endblock %}

AbdealiLoKo commented 10 years ago
  1. Use the backticks : Check inline code in https://guides.github.com/features/mastering-markdown/ You should always write code in this form small code
long bit of code
    with indents
  1. What exactly is the error ? Error messages are good for debugging purposes.
akshayutture commented 10 years ago

No error message is being shown. The dajaxice part of the javascript just isnt working . I tried this tutorial but on clicking the button nothing happens. There is no error message on the browser or the terminal. . http://django-dajaxice.readthedocs.org/en/latest/quickstart.html

AbdealiLoKo commented 10 years ago

In chrome check the "netowork" tab. Does the request go to the server ? It'll show something like

apps.users.get_info/
/dajaxice

on the left column. Where the names will be changed depending on your function.

Try running the code through Terminal Dajaxice.apps.portals.events.args_example(function(response) { console.log(response); }, {'text' : 'kdrgnkrs' })

I just saw your events2.html, there is no button nor is there any javascript code... Did you read the examples properly ?

  1. There needs to be a dajaxice function.
  2. You need to include the dajaxice's javascript files
  3. You need to call the js function with the necessary arguments
  4. You need to use the response it gives to do something on the screen

On Sat, Jun 28, 2014 at 7:56 PM, akshayutture notifications@github.com wrote:

No error message is being shown. The dajaxice part of the javascript just isnt working . I tried this tutorial but on clicking the button nothing happens. There is no error message on the browser or the terminal. . http://django-dajaxice.readthedocs.org/en/latest/quickstart.html

Reply to this email directly or view it on GitHub https://github.com/The-WebOps-Club/fest-api/issues/101#issuecomment-47428790 .

akshayutture commented 10 years ago

Sorry I printed the wrong html here. The correct one is given below.

HTML {% extends 'base/base.html' %} {% load check_access %}

{% block content %}

{% load dajaxice_templatetags %}

{% dajaxice_js_import %} {% csrf_token %}

<input type="button" onclick="Dajaxice.apps.portals.events.sayhello(my_callback)" value="Get 
   message from server!"> 555nhjh5
<script>
function my_callback(data){
    alert(data.message);
}
</script>

{% endblock %}

AJAX.PY

from django.utils import simplejson from dajaxice.decorators import dajaxice_register

@dajaxice_register def sayhello(request): return simplejson.dumps({'message':'Hello World'})

AbdealiLoKo commented 10 years ago

I still do not see any javascript nor buttons mate :/

On Sun, Jun 29, 2014 at 1:19 PM, akshayutture notifications@github.com wrote:

Sorry I printed the wrong html here. The correct one is given below I tried a dozen variations

HTML

{% extends 'base/base.html' %} {% load check_access %}

{% block content %}

{% load dajaxice_templatetags %}

{% dajaxice_js_import %} {% csrf_token %} 555nhjh5

{% endblock %}

AJAX.PY

from django.utils import simplejson from dajaxice.decorators import dajaxice_register

@dajaxice_register def sayhello(request): return simplejson.dumps({'message':'Hello World'})

Reply to this email directly or view it on GitHub https://github.com/The-WebOps-Club/fest-api/issues/101#issuecomment-47448137 .

akshayutture commented 10 years ago

I think the javascript part isnt getting printed here. I'll send you a mail

AbdealiLoKo commented 10 years ago

No, dont do that. Post your code with backticks ... as i had mentioned before. If you dont tell github ur putting code, obviously github will get confused no

On Sun, Jun 29, 2014 at 1:24 PM, akshayutture notifications@github.com wrote:

I think the javascript part isnt getting printed here. I'll send you a mail

Reply to this email directly or view it on GitHub https://github.com/The-WebOps-Club/fest-api/issues/101#issuecomment-47448207 .

akshayutture commented 10 years ago

Okay. Edited the above comment to include the html and js

AbdealiLoKo commented 10 years ago

Try runnibg what you wrote in onclick in chrome debuggers console tab On Jun 29, 2014 1:33 PM, "akshayutture" notifications@github.com wrote:

Okay. Edited the above comment to include the html and js

Reply to this email directly or view it on GitHub https://github.com/The-WebOps-Club/fest-api/issues/101#issuecomment-47448330 .

akshayutture commented 10 years ago

Resource interpreted as Script but transferred with MIME type application/octet-stream: "http://localhost:8000/static/dajaxice/dajaxice.core.js". (index):699 GET http://graph.facebook.com/Fest%20API/picture?height=60&width=60 404 (Not Found) jquery-1.11.0.js:8231 3 Uncaught TypeError: Cannot read property 'sayhello' of undefined

AbdealiLoKo commented 10 years ago

Try writing dajaxice.apps and dajaxice.apps.portals and check if they exist. If they don't, restart your server and refresh. If there's an error in dajaxice it'll come only for the first time you open a page after restarting server On Jun 29, 2014 1:37 PM, "akshayutture" notifications@github.com wrote:

Resource interpreted as Script but transferred with MIME type application/octet-stream: " http://localhost:8000/static/dajaxice/dajaxice.core.js". (index):699 GET http://graph.facebook.com/Fest%20API/picture?height=60&width=60 404 (Not Found) jquery-1.11.0.js:8231 3 Uncaught TypeError: Cannot read property 'sayhello' of undefined

Reply to this email directly or view it on GitHub https://github.com/The-WebOps-Club/fest-api/issues/101#issuecomment-47448386 .

AbdealiLoKo commented 10 years ago

In the console tab of chromes debugger (ctrl shift j) On Jun 29, 2014 1:45 PM, "akshayutture" notifications@github.com wrote:

where do i write dajaxice.apps and dajaxice.appsanddajaxice.apps.portals

Reply to this email directly or view it on GitHub https://github.com/The-WebOps-Club/fest-api/issues/101#issuecomment-47448506 .

akshayutture commented 10 years ago

dajaxice.apps ReferenceError: dajaxice is not defined

AbdealiLoKo commented 10 years ago

its cappital D ... i was on phone so it was difficult to type

On Sun, Jun 29, 2014 at 1:48 PM, akshayutture notifications@github.com wrote:

dajaxice.apps ReferenceError: dajaxice is not defined

Reply to this email directly or view it on GitHub https://github.com/The-WebOps-Club/fest-api/issues/101#issuecomment-47448561 .