On Tue, Jul 2, 2013 at 4:24 PM, Sithembewena Lloyd Dube
<[email protected]> 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.
>
>
> On Wed, Jul 3, 2013 at 12:06 AM, Larry Martell <[email protected]>
> wrote:
>>
>> I'm invoking a view from an ajax call and I want to return data. But
>> the browser interpertates the return as a 500 (internal sever error)
>> and my ajax success function does not get called. How can I return a
>> successful status (like a 201) and also return data?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
>
>
> --
> Regards,
> Sithu Lloyd Dube
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.