I think the problem might be that you're using the getJSON function, which
expects a JSON response, but your view returns 'OK', which is not valid
JSON. The callback you have given to getJSON only gets called on "success"
(meaning a JSON document was retrieved) - that's why nothing is happening
for you right now. Try changing the return value from the view to a string
containing:

{"ok": true}

And then change this line in the JavaScript:

if (data == 'OK') {

to:

if (data.ok) {

I think it should work with those changes. If it doesn't, try checking the
JavaScript console in your browser for any errors.

Brett


On 12/14/11 4:03 PM, "yun li" <yli0...@gmail.com> wrote:

>But it still cannot work. when I submit something, it goes to the
>please_wait page showing "please wait" and then nothing happened. I
>really have no knowledge on ajax, so is there something I need to
>install or import in my projects? and how can I test if codes in
><script> ...</script> really invoked?
>
>Thanks,
>
>On 12月14日, 下午1时47分, Brett Epps <brett.e...@quest.com> wrote:
>> I think the problem is that your <script> tag is incorrect. You're using
>> the same one to load jQuery and to add your code, so your JavaScript is
>> not getting run. The file "please_wait.html" should look like this:
>>
>> <!DOCTYPE html>
>> <html>
>>     <head>
>>         <title>Please wait.</title>
>>         <meta charset="utf-8">
>>         <script 
>>src="http://code.jquery.com/jquery-1.7.1.min.js";></script>
>>         <script>
>>             $(function() {
>>                 $.getJSON('{% url run_DHM %}', function(data) {
>>                     if (data == 'OK') {
>>                         window.location.href = '{% url displayDHM %}';
>>                     } else {
>>                         alert(data);
>>                     }
>>                 });
>>             });
>>         </script>
>>     </head>
>>     <body>
>>         <p>Please wait.</p>
>>     </body>
>> </html>
>>
>> I've also added a bit more to the HTML file so that it is more
>> standards-compliant.
>>
>> Brett
>>
>> On 12/14/11 1:23 PM, "yun li" <yli0...@gmail.com> wrote:
>>
>>
>>
>>
>>
>>
>>
>> >Hi,
>> >Does anyone can help?
>> >Here are all contents in my files, I tried variable ways, but when I
>> >submit a form, it only return the please_wait page and then stay there
>> >forever. There is no redirect happened.
>> >Since I want to check if it works first, there is no actual
>> >calculation in the code.
>>
>> >#########  url.py  ################
>> >urlpatterns = patterns('',
>> >    (r'^test$',views.test_form),
>> >    (r'^please_wait', views.please_wait),
>> >    url(r'^run_DHM$', views.run_DHM, name="run_DHM") ,
>> >    url(r'^displayDHM', views.display_DHM, name="displayDHM")
>> >)
>>
>> >########### view.py #############
>> >def test_form(request):
>> >    return render_to_response('test.html')
>>
>> >def please_wait(request):
>> >    return render_to_response('please_wait.html')
>>
>> >def run_DHM(request):
>> >       ### lengthy calculations... ...
>> >    return HttpResponse("OK")
>>
>> >def display_DHM(request):
>> >    return render_to_response('display_DHM.html')
>>
>> >########## test.html ###########
>> >{% extends "baseFrame.html" %}
>>
>> >{% block maincontent %}
>> >  <form method="POST" action="please_wait">
>> >   <p>Test:</p>
>> >   <div id="address"></div>
>> >   <p>Type your value in here:</p>
>> >   <p><textarea name="order" rows="6" cols="50" id="order"></
>> >textarea></p>
>> >   <p><input type="submit" value="submit" id="submit" /></p>
>> >  </form>
>> >{% endblock %}
>>
>> >########### please_wait.html ##########
>>
>> ><html>Please wait
>> ><script type="text/javascript" src="http://code.jquery.com/
>> >jquery-1.7.1.min.js">
>> >$.getJSON('{% url run_DHM %}', function(data) {
>> >    if (data == 'OK') {
>> >                  window.location.href = '{% url displayDHM %}';
>> >            } else {
>> >                  alert(data);
>> >            }
>> >    });
>> ></script>
>> ></html>
>>
>> >###########  display_DHM.html #########
>> ><HTML>
>> ><BODY>END FINALLY!</BODY>
>> ></HTML>
>>
>> >--
>> >You received this message because you are subscribed to the Google
>>Groups
>> >"Django users" group.
>> >To post to this group, send email to django-users@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.
>
>-- 
>You received this message because you are subscribed to the Google Groups
>"Django users" group.
>To post to this group, send email to django-users@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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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