On Tue, Jul 2, 2013 at 4:24 PM, Sithembewena Lloyd Dube
<
zeb...@gmail.com> wrote:
> What data format is your view returning? Django views return HTTP response
> objects (by default, at least) - although Python lists (and other Python
> collections?) should work when passed into a view in its context (I have
> found Django querysets to be an exception).
>
> AJAX is Asynchronous Javascript, so I presume that an AJAX call would expect
> something like JSON output from a callable. I guess with some pain one could
> get Javascript to ingest Django querysets? I couldn't think of a sensible
> reason to do so - and I stand to be corrected.
I want to return a string. 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.