AJAX HTTP请求在drupal中终止异常警报

时间:2013-06-03 09:00:12

标签: ajax drupal

在我的drupal视图中我激活了Ajax,在我的前端一切正常但是当用户发出ajax请求然后他切换到另一页(在他从ajax请求得到响应之前)我看到了这个警告

An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /en/views/ajax
StatusText: 
ResponseText: 
ReadyState: 4

2 个答案:

答案 0 :(得分:1)

发生此错误是因为它是在Drupal中处理AJAX错误的标准方法。如果您提交表单,则在处理AJAX请求时会收到错误。

实际上,这个错误是Drupal和Drupal的目的,通过misc/drupal.jsDrupal.ajax.prototype.error = function (response, uri)一起在Drupal.ajaxError = function (xmlhttp, uri)文件的Drupal 7中抛出此错误。

请注意,这是一个UX问题,而不是一个bug。

Drupal网站上有关于Drupal alerts "An AJAX HTTP request terminated abnormally" during normal site operation, confusing site visitors/editors修复Drupal 8的未解决问题。

对于Drupal 7,您可以尝试应用以下核心补丁:D7-fix_autocomplete_terminated_error-1232416-179-do-not-test.patch,如下所示:

--- a/misc/ajax.js
+++ b/misc/ajax.js
@@ -448,7 +448,10 @@ Drupal.ajax.prototype.getEffect = function (response) {
  * Handler for the form redirection error.
  */
 Drupal.ajax.prototype.error = function (response, uri) {
-  alert(Drupal.ajaxError(response, uri));
+  // Fix for autocomplete terminated error.
+  if (response.status != 0) {
+    alert(Drupal.ajaxError(response, uri));
+  }
   // Remove the progress element.
   if (this.progress.element) {
     $(this.progress.element).remove();
diff --git a/misc/autocomplete.js b/misc/autocomplete.js
index 8f7ac60..980c1ca 100644
--- a/misc/autocomplete.js
+++ b/misc/autocomplete.js
@@ -306,7 +306,10 @@ Drupal.ACDB.prototype.search = function (searchString) {
         }
       },
       error: function (xmlhttp) {
-        alert(Drupal.ajaxError(xmlhttp, db.uri));
+        // Fix for autocomplete terminated error.
+        if (xmlhttp.status != 0) {
+          alert(Drupal.ajaxError(xmlhttp, db.uri));
+        }
       }
     });
   }, this.delay);

答案 1 :(得分:0)

这是解决问题的简单方法:

   $(document).ajaxError(function() {
         donotshowajayerror; // prevent ajax errors alerts
});

写下一些破碎的代码,这样就会停止在该行执行javascript。