0

I cannot get a response from server.. my ajax request from html hit the view in django and django returns an response, but callback function not receiving anything... Where is the problem? Here is my code:

$.ajax({ // create an AJAX call...
                type: "GET", // GET or POST
                url: "djuka/", // the file to call
                dataType: "json",
                contentType: 'application/json',
                success: function(response) { // on success..
                    alert("aaaa");
                }
            });

and view:

def djuka(request):
if request.is_ajax():
    print "-->YES"
return HttpResponse(json.dumps({'message' : 'awesome'},ensure_ascii=False), mimetype='application/javascript')

print "-->YES" is executed but alert("aaaa") is never called.....

milandjukic88
  • 1,065
  • 3
  • 13
  • 30

1 Answers1

0

Try removing the print statement. It's making the response invalid JSON.

JAL
  • 21,295
  • 1
  • 48
  • 66
  • Check out A. Wolff's suggestions in the comment. You can debug this by using the browser's console and the $.ajax error call back. – JAL Sep 08 '13 at 09:55
  • Sorry i didnt see that answer :) – milandjukic88 Sep 08 '13 at 10:09
  • I am new in ajax... so did you mean something like this: error: function(xhr, error){ alert("aaa"); console.debug(xhr); console.debug(error); } – milandjukic88 Sep 08 '13 at 10:10
  • Yes, that should give you some useful messages... Or, lack of messages indicates something too. What happens when you go to the django URL in your browser? – JAL Sep 08 '13 at 10:35
  • Hm, when i go directly to that link i get {"message": "awesome"} but i dont get response to ajax.... – milandjukic88 Sep 08 '13 at 10:38
  • Anyone? :) I am trying whole day and nothing :) – milandjukic88 Sep 08 '13 at 21:45
  • I think you need to set the mime type to application/json. See http://stackoverflow.com/questions/2428092/creating-a-json-response-using-django-and-python – JAL Sep 09 '13 at 01:22