0

I have read all on the theme but I can't understand what's wrong.

$(document).ready(function() { $.post("tweet.py", { lat : searchResult._point.__lat, lng : searchResult._point.__lng, text : searchResult.text }, function(data) { alert(data); }); }); 

The handler's code:

import django def iEventAjax(request): if request.is_ajax(): return HttpResponse("ok") 

The alert message is

"import django def iEventAjax(request): if request.is_ajax(): return HttpResponse("ok") " 

instead of "ok"

what's wrong?

4
  • Surely you have to post to a URL on your server, not to a file. Commented Nov 4, 2011 at 10:57
  • what should i write instead? $.post("/", { ? Commented Nov 4, 2011 at 11:01
  • which url? i have two file in the project directory, the file that contains js and html from where i send post and file tweet.py Commented Nov 4, 2011 at 11:03
  • Well you presumably know how to write URLconfs in Django. One of the URLs in that URLconf is (also presumably) connected to your "handler" function. So that's the URL you want to be posting to. Commented Nov 4, 2011 at 11:03

1 Answer 1

1

Please add in your urls.py an url like

(r'^ajaxrequest$', 'app.views.iEventAjax') 

and then change

$(document).ready(function() { $.post("/ajaxrequest", { lat : searchResult._point.__lat, lng : searchResult._point.__lng, text : searchResult.text }, function(data) { alert(data); }); }); 

in your views.py of your app

def iEventAjax(request): return HttpResponse("ok") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.