returning data to ajax call

returning data to ajax call

I'm invoking a python script from an ajax call (using django) and I want to return data. I've never done this before. I've been reading examples on the web and I came up with this:

  1. $.ajax({
  2.     url: 'permalink/',
  3.     type: 'GET',
  4.     data: {
  5.         report: "{% url motor.core.reports.views.view
  6. the_controller.app.name the_controller.get_name %}",
  7.         params: "{{ the_report.params_string }}"
  8.     },
  9.     dataType: 'json',
  10.     success: function (data) {
  11.         setTimeout(function () {
  12.             alert(data);
  13.         }, 0);
  14.     }
  15. });

In my function I first tried returning just the string, but that was causing a 500 error. Then I tried this:

return HttpResponse(content=data, content_type="text/plain", status=201)

I don't get the error, but the ajax success function does not seem to be called. Looking at the network info in the browser I see this:






In the browser the response has this:

HTTP/1.0 201 OK
Date: Tue, 02 Jul 2013 22:53:47 GMT
Server: WSGIServer/0.1 Python/2.7.2
Vary: Cookie
Content-Type: text/plain

No content. But I verified from pdb that the python code is sending something in the content when it does this:

return HttpResponse(content=data, content_type="text/plain", status=201)










What am I doing wrong? How do I return the data correctly?