On Wed, Jul 3, 2013 at 10:01 AM, C. Kirby <[email protected]> wrote:
> I'm sorry, I was typing without thinking.
> render_to_string() if you want to use a template without headers
> render_to_response() includes headers
>
> HttpResponse(json.dumps(data_object)) should be what you want.
>
> It would also be helpful to see the code for your view. It looks like you
> already put the template code concerning the ajax call in this thread.

The view is very simple. It does some stuff and ends up with a single
short string that I am returning like this:

    return HttpResponse(data, content_type="application/json", status=200)

I can pick up the string in an always function from data.responseText
so I'm going to go with that, declare victory and move on. Thanks to
everyone for the help.


>
> On Wednesday, July 3, 2013 10:47:38 AM UTC-5, [email protected] wrote:
>>
>> On Wed, Jul 3, 2013 at 9:30 AM, C. Kirby <[email protected]> wrote:
>> > An HttpResponse includes http headers and will blow up an ajax call.
>> > You want to use a render_to_string method and pass either json or a
>> > rendered
>> > template (render to string bypasses the headers, render to response will
>> > include them)
>>
>> I don't want to return a template, just some data. I tried this:
>>
>>     return render_to_string(simplejson.dumps(data))
>>
>> But it blows up with template not found.
>>
>> > On Wednesday, July 3, 2013 8:14:06 AM UTC-5, [email protected] wrote:
>> >>
>> >> On Tue, Jul 2, 2013 at 5:39 PM, Larry Martell <[email protected]>
>> >> wrote:
>> >> > On Tue, Jul 2, 2013 at 5:24 PM, Sanjay Bhangar <[email protected]>
>> >> > wrote:
>> >> >> On Tue, Jul 2, 2013 at 4:20 PM, Larry Martell <[email protected]>
>> >> >> wrote:
>> >> >>>
>> >> >>> On Tue, Jul 2, 2013 at 5:14 PM, Sanjay Bhangar
>> >> >>> <[email protected]>
>> >> >>> wrote:
>> >> >>> > On Tue, Jul 2, 2013 at 4:01 PM, Larry Martell
>> >> >>> > <[email protected]>
>> >> >>> > wrote:
>> >> >>> >>
>> >> >>> >> <snip />
>> >> >>> >>
>> >> >>> >> In the browser the response has this:
>> >> >>> >>
>> >> >>> >> HTTP/1.0 200 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=200)
>> >> >>> >>
>> >> >>> > try:
>> >> >>> >   return HttpResponse(data, content_type="text/plain",
>> >> >>> > status=200)
>> >> >>> >
>> >> >>> > (no content= ... )
>> >> >>>
>> >> >>> No difference - still no content.
>> >> >>>
>> >> >> Can you navigate to the page just in the browser (not making an AJAX
>> >> >> request) ? Do you get a response then? What if you substitute data
>> >> >> with
>> >> >> "some random string" ?
>> >> >
>> >> > Yes, I get back the data I expect.
>> >>
>> >> I just tried setting an always function and that is called and I can
>> >> get my response. So I guess I'll go with that. But I wonder why the
>> >> success function is not called.
>> >
>> > --
>> > 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.
>
>

-- 
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.


Reply via email to