It seems as if this is the only solution but after a week of trying to
implement it in a variety of ways it won't work. is there something I
need to download (jquery)? More helpful would be a real HTML page as
an example or a live example on the web. I am sorry for the trouble
but I'd like to understand this and get it working.

On Tue, Aug 31, 2010 at 7:37 PM, Alec Shaner <asha...@chumpland.org> wrote:
> $.getJSON should be embedded in your initial Page Wait response page. The
> first argument isn't a view, rather a URL. So you might want to use the
> django url template tag, e.g.,
> $.getJSON('{% url whatever.run_DHM %}', ...)
> The second argument is a callback function. The browser stores the callback
> and subsequently calls it when the url requested returns a response. It also
> might be confusing because the function is defined inline (anonymous), which
> is a frequent shortcut used in javascript. But anyway, when the callback
> function executes he just put console.log(result.data) as way to see what
> gets returned.
>  You say you want to send the user to another page with the results, but you
> could return a rendered chunk of html code and replace the Please Wait
> message using jquery to mainupulate the DOM (jquery documentation has
> tutorials). Or if you want to redirect to a new page you could store the
> calculation results in the session and redirect to a view that pulls from
> that same session data (or use memcached). So maybe instead of
> console.log(result.data), you could
> use window.location="/some/url/to/show/calculations/";
> His example returns a HttpResponse just to illustrate the concept of how to
> return JSON data. You don't have to return JSON, but it's a good method if
> you want to return structured data. In the above example of a redirect you
> could just return anything I suppose, i.e., just an 'OK'.
>
> On Tue, Aug 31, 2010 at 5:11 PM, Bradley Hintze
> <bradle...@aggiemail.usu.edu> wrote:
>>
>> Ok, I'll try to elaborate. again java is foreign to me although I've
>> spent all day trying to learn some.
>>  Here's the code:
>>
>> def please_wait(request):
>>   # ... setup context or something
>>   return render_to_response("please_wait.html")
>>
>> def run_DHM(request)
>>   # ... perform calculations and collect the result in a dict
>>   data = {"result": something}
>>   return HttpResponse(json.dumps(data), mimetype="application/json")
>>
>>
>> # using jquery in your html
>> <script type="text/javascript">
>> $.getJSON("/run_DHM/", function(data) {
>>   // do something with result
>>   console.log(data.result);
>> });
>> </script>
>>
>> def run_DHM(request) is straight forward then it falls apart.
>>
>> $.getJSON("/run_DHM/", function(data) {
>>   // do something with result
>>   console.log(data.result);
>> });
>>
>> I presume that '$.getJSON("/run_DHM/", function(data)' somehow runs
>> the run_DHM function? How can it even find the function since it lives
>> in view.py? '// do something with result'???? I want to send another
>> page to the client with the results but do I do this here? If not,
>> what do I do here? What does 'console.log(data.result);' do? Why does
>> def run_DHM(request) return a HttpResponse? I have a template I want
>> it to return so shouldn't I use render_to_response? Obviously, I am
>> not getting how the javascript works so I have no idea how to set this
>> up. I was hoping there was a pythonic solution :).
>>
>> I hope this explains my utter confusion sufficiently.
>>
>> Bradley
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
801-712-8799

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to