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:
- $.ajax({
- url: 'permalink/',
- type: 'GET',
- data: {
- report: "{% url motor.core.reports.views.view
- the_controller.app.name the_controller.get_name %}",
- params: "{{ the_report.params_string }}"
- },
- dataType: 'json',
- success: function (data) {
- setTimeout(function () {
- alert(data);
- }, 0);
- }
- });
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?