| | 15 | } |
| | 16 | |
| | 17 | |
| | 18 | function replace_complete_page(html) { |
| | 19 | // replace the complete page |
| | 20 | document.open() // no append available since it is closed |
| | 21 | document.write(html); |
| | 22 | document.close(); |
| | 23 | } |
| | 24 | |
| | 25 | function replace_page_content(data, textStatus) { |
| | 26 | /************************************************************************* |
| | 27 | ajax success "handler". |
| | 28 | replace the "#page_content" with the new html response data |
| | 29 | *************************************************************************/ |
| | 30 | log("ajax post response success."); |
| | 31 | log("status:" + textStatus); |
| | 32 | if (data.indexOf("</body>") != -1) { |
| | 33 | // FIXME: We should find a way to handle a |
| | 34 | // redirect directly. But we always get the |
| | 35 | // html data of the redirected page. |
| | 36 | |
| | 37 | log("redirect work-a-round: replace the complete page"); |
| | 38 | log("</body> index:" + data.indexOf("</body>")); |
| | 39 | replace_complete_page(data) |
| | 40 | } else { |
| | 41 | $("#page_content").html(data); |
| | 42 | $("#page_content").animate({opacity: 1}, 500 ); |
| | 43 | } |
| | 44 | load_normal_link = false; |
| | 45 | } |
| | 46 | |
| | 47 | |
| | 48 | function ajax_error_handler(XMLHttpRequest, textStatus, errorThrown) { |
| | 49 | /************************************************************************* |
| | 50 | ajax error "handler". |
| | 51 | replace the complete page with the error text (django html traceback page) |
| | 52 | *************************************************************************/ |
| | 53 | log("ajax get response error!"); |
| | 54 | log(XMLHttpRequest); |
| | 55 | var response_text = XMLHttpRequest.responseText; |
| | 56 | log("response_text: '" + response_text + "'"); |
| | 57 | if (!response_text) { |
| | 58 | response_text = "<h1>Ajax response error without any response text.</h1>"; |
| | 59 | } |
| | 60 | replace_complete_page(response_text); |
| | 61 | load_normal_link = true; |
| 54 | | success: function(form_html){ |
| 55 | | log("ajax post response success."); |
| 56 | | $("#page_content").html(form_html); |
| 57 | | $("#page_content").animate({opacity: 1}, 500 ); |
| 58 | | load_normal_link = false; |
| | 101 | success: replace_page_content, |
| | 102 | complete: function(XMLHttpRequest, textStatus){ |
| | 103 | // Handle redirects |
| | 104 | log("complete:" + XMLHttpRequest); |
| | 105 | log("text:" + textStatus); |
| | 106 | log("complete:" + XMLHttpRequest.status); |
| | 107 | log("complete:" + XMLHttpRequest.getResponseHeader('Location')); |
| | 108 | |
| | 109 | if(XMLHttpRequest.status.toString()[0]=='3'){ |
| | 110 | top.location.href = XMLHttpRequest.getResponseHeader('Location'); |
| | 111 | } |
| 60 | | error: function(XMLHttpRequest){ |
| 61 | | log("ajax get response error!"); |
| 62 | | // Display the complete Traceback html page |
| 63 | | log(XMLHttpRequest); |
| 64 | | var response_text = XMLHttpRequest.responseText; |
| 65 | | log("response_text: '" + response_text + "'"); |
| 66 | | if (!response_text) { |
| 67 | | document.write("<h1>ajax response error</h1>"); |
| 68 | | } else { |
| 69 | | document.write(response_text); |
| 70 | | } |
| 71 | | load_normal_link = true; |
| 72 | | } |
| 73 | | }); |
| | 113 | error: ajax_error_handler |
| | 114 | }); |
| | 115 | log("ajax done:" + XMLHttpRequest); |
| | 116 | log("ajax done:" + XMLHttpRequest.status); |
| | 117 | log("ajax done:" + XMLHttpRequest.getResponseHeader('Location')); |
| 114 | | success: function(form_html){ |
| 115 | | log("ajax get success."); |
| 116 | | $("#page_content").html(form_html); |
| 117 | | $("#page_content").animate({opacity: 1}, 500 ); |
| 118 | | load_normal_link = false; |
| 119 | | }, |
| 120 | | error: function(XMLHttpRequest){ |
| 121 | | log("ajax get response error!"); |
| 122 | | // Display the complete Traceback html page |
| 123 | | log(XMLHttpRequest); |
| 124 | | var response_text = XMLHttpRequest.responseText; |
| 125 | | log("response_text: '" + response_text + "'"); |
| 126 | | if (!response_text) { |
| 127 | | document.write("<h1>ajax response error</h1>"); |
| 128 | | } else { |
| 129 | | document.write(response_text); |
| 130 | | } |
| 131 | | load_normal_link = true; |
| 132 | | } |
| | 158 | success: replace_page_content, |
| | 159 | error: ajax_error_handler |