Hi all.
I created a view, show as "block", in settings included Ajax, useing pager. Then I go to the page that displays the block, click on the next page (1 of 2 ››), nothing happens and FireBug wrote JS error:

Drupal.Views.Ajax.handleErrors is not a function
[Break on this error] error: function(xhr)...ews-throbbing', object).remove(); },
.../sites/all/modules/views/js/ajax_view.js?N (line 156)

Maybe someone has encountered the same problem... Searching does not help.

Files: 
CommentFileSizeAuthor
#9 ajax.error_.handle.patch2.34 KBkratkar
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in ajax.error_.handle.patch.
[ View ]
#5 ajax_view.zip2.73 KBkratkar

Comments

Add the function of Drupal.Views.Ajax.handleErrors /sites/all/modules/views/ajax.js in (modules_dir) /sites/all/modules/views/ajax_view.js. But will still be some error (alert error), he is now corrected with this error)))

I added a file (ajax_view.js) in module_dir — the same problem..
And what did you mean when you wrote "he is now corrected with this error"? I need to update the module views or what?

not what I wanted to write or can translate.google.com))
In the file/sites/all/modules/views/js/ajax_view.js Drupal.Views.Ajax.handleErrors add function from the file/sites/all/modules/views/js/ajax.js (at the bottom somewhere).
Further problem with the encode json:
should be replaced by a function drupal_to_js (common.php)
line 2499

return '"'. str_replace(array("\r", "\n", "<", ">", "&"),
                              array('\r', '\n', '\x3c', '\x3e', '\x26'),
                              addslashes($var)) .'"';

to a new
$replace_pairs = array(
        // ", \ and U+0000 - U+001F must be escaped according to RFC 4627.
        '\\' => '\u005c',
        '"' => '\u0022',
        "\x00" => '\u0000',
        "\x01" => '\u0001',
        "\x02" => '\u0002',
        "\x03" => '\u0003',
        "\x04" => '\u0004',
        "\x05" => '\u0005',
        "\x06" => '\u0006',
        "\x07" => '\u0007',
        "\x08" => '\u0008',
        "\x09" => '\u0009',
        "\x0a" => '\u000a',
        "\x0b" => '\u000b',
        "\x0c" => '\u000c',
        "\x0d" => '\u000d',
        "\x0e" => '\u000e',
        "\x0f" => '\u000f',
        "\x10" => '\u0010',
        "\x11" => '\u0011',
        "\x12" => '\u0012',
        "\x13" => '\u0013',
        "\x14" => '\u0014',
        "\x15" => '\u0015',
        "\x16" => '\u0016',
        "\x17" => '\u0017',
        "\x18" => '\u0018',
        "\x19" => '\u0019',
        "\x1a" => '\u001a',
        "\x1b" => '\u001b',
        "\x1c" => '\u001c',
        "\x1d" => '\u001d',
        "\x1e" => '\u001e',
        "\x1f" => '\u001f',
        // Prevent browsers from interpreting these as as special.
        "'" => '\u0027',
        '<' => '\u003c',
        '>' => '\u003e',
        '&' => '\u0026',
        // Prevent browsers from interpreting the solidus as special and
        // non-compliant JSON parsers from interpreting // as a comment.
        '/' => '\u002f',
        // While these are allowed unescaped according to ECMA-262, section
        // 15.12.2, they cause problems in some JSON parser.
        "\xe2\x80\xa8" => '\u2028', // U+2028, Line Separator.
        "\xe2\x80\xa9" => '\u2029', // U+2029, Paragraph Separator.
      );
      return '"'. strtr($var, $replace_pairs) .'"';

I picked up from the last patch d7.
And you can string 2536 (drupal_set_header ('Content-Type: text / javascript; charset = utf-8')) is replaced by drupal_set_header ('Content-Type: application / json;');
Bear in mind you change in the core CMS))

In the file/sites/all/modules/views/js/ajax_view.js Drupal.Views.Ajax.handleErrors add function from the file/sites/all/modules/views/js/ajax.js (at the bottom somewhere).

What and where exactly do i need to add this function?) It would be better if you show me file)
For example, i add: Drupal.Views.Ajax.handleErrors(); at the very bottom of the file. Is it correct?

StatusFileSize
new2.73 KB

file : /sites/all/modules/views/js/ajax.js line 334:

/**
* Display error in a more fashion way
*/
Drupal.Views.Ajax.handleErrors = function (xhr, path) {
  var error_text = '';
  if ((xhr.status == 500 && xhr.responseText) || xhr.status == 200) {
    error_text = xhr.responseText;
    // Replace all &lt; and &gt; by < and >
    error_text = error_text.replace("/&(lt|gt);/g", function (m, p) {
      return (p == "lt")? "<" : ">";
    });
    // Now, replace all html tags by empty spaces
    error_text = error_text.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi,"");
    // Fix end lines
    error_text = error_text.replace(/[\n]+\s+/g,"\n");
  }
  else if (xhr.status == 500) {
    error_text = xhr.status + ': ' + Drupal.t("Internal server error. Please see server or PHP logs for error information.");
  }
  else {
    error_text = xhr.status + ': ' + xhr.statusText;
  }
  alert(Drupal.t("An error occurred at @path.\n\nError Description: @error", {'@path': path, '@error': error_text}));
}

add in file sites/all/modules/views/js/ajax_view.js
Look for attachment.)

So, the error in alert is: "parsererror" :) now what?))

/incudes/common.php line 2499 (function drupal_to_js)...
more here: http://drupal.org/node/914360#comment-3468550 ))

Карен, спасибо огромное! Помогло :) жаль только системный модуль затрагивается..

StatusFileSize
new2.34 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in ajax.error_.handle.patch.
[ View ]

Мне за что))

Here is a patch to fix a problem in ajax_view.js (no function Drupal.Views.Ajax.handleErrors).
But does not solve the problem of parsing json function drupal_to_js

Version:6.x-2.9» 6.x-2.x-dev
Status:Active» Needs review

I had the same problem and this solution helped.

Thanks!

Status:Needs review» Needs work

+  else if(textStatus=='timeout'){
+      error_text = Drupal.t("The server doesn't answer. Time out.");
+  }
+  else if(textStatus=='parsererror') {
+      error_text = Drupal.t("Error while parsing code");
+  }
+  else {
+    error_text = xhr.status + ': ' + xhr.statusText;
+  }

Could you use drupal code style? Thanks!

Won't it be simpler to just include the ajax.js file too? Am I missing something?

I had similar symptoms. Though the button would work on the second click. A 302 redirect was being called by Secure Pages module... which then threw an error and caused views to call the non-existent function.

The ajax path being used by views was not properly whitelisted in Secure Pages configuration. Adding "views/ajax*" to the whitelist section resolved the issue for me. Hope this helps someone.

related to #3, i found i was getting this problem because of U+2028 characters in pasted text. the code in #3 prevents the json ajax error from Views, but it still failed - i had to replace those characters with blanks. see #479368: D7: Create RFC compliant HTML safe JSON

i had the same issue but the above solution fixed my issue Thank you kratkar

Steps i have followed
1) Added the function Drupal.Views.Ajax.handleErrors to /modules/view/js/ajax_view.js
/**
* Display error in a more fashion way
*/
Drupal.Views.Ajax.handleErrors = function (xhr, path) {
var error_text = '';

if ((xhr.status == 500 && xhr.responseText) || xhr.status == 200) {
error_text = xhr.responseText;

// Replace all < and > by < and >
error_text = error_text.replace("/&(lt|gt);/g", function (m, p) {
return (p == "lt")? "<" : ">";
});

// Now, replace all html tags by empty spaces
error_text = error_text.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi,"");

// Fix end lines
error_text = error_text.replace(/[\n]+\s+/g,"\n");
}
else if (xhr.status == 500) {
error_text = xhr.status + ': ' + Drupal.t("Internal server error. Please see server or PHP logs for error information.");
}
else {
error_text = xhr.status + ': ' + xhr.statusText;
}

alert(Drupal.t("An error occurred at @path.\n\nError Description: @error", {'@path': path, '@error': error_text}));
}

2) Changed the below line in /includes/common.js inside the function drupal_to_js
return '"'. str_replace(array("\r", "\n", "<", ">", "&"),
array('\r', '\n', '\x3c', '\x3e', '\x26'),
addslashes($var)) .'"';

to

$replace_pairs = array(
// ", \ and U+0000 - U+001F must be escaped according to RFC 4627.
'\\' => '\u005c',
'"' => '\u0022',
"\x00" => '\u0000',
"\x01" => '\u0001',
"\x02" => '\u0002',
"\x03" => '\u0003',
"\x04" => '\u0004',
"\x05" => '\u0005',
"\x06" => '\u0006',
"\x07" => '\u0007',
"\x08" => '\u0008',
"\x09" => '\u0009',
"\x0a" => '\u000a',
"\x0b" => '\u000b',
"\x0c" => '\u000c',
"\x0d" => '\u000d',
"\x0e" => '\u000e',
"\x0f" => '\u000f',
"\x10" => '\u0010',
"\x11" => '\u0011',
"\x12" => '\u0012',
"\x13" => '\u0013',
"\x14" => '\u0014',
"\x15" => '\u0015',
"\x16" => '\u0016',
"\x17" => '\u0017',
"\x18" => '\u0018',
"\x19" => '\u0019',
"\x1a" => '\u001a',
"\x1b" => '\u001b',
"\x1c" => '\u001c',
"\x1d" => '\u001d',
"\x1e" => '\u001e',
"\x1f" => '\u001f',
// Prevent browsers from interpreting these as as special.
"'" => '\u0027',
'<' => '\u003c',
'>' => '\u003e',
'&' => '\u0026',
// Prevent browsers from interpreting the solidus as special and
// non-compliant JSON parsers from interpreting // as a comment.
'/' => '\u002f',
// While these are allowed unescaped according to ECMA-262, section
// 15.12.2, they cause problems in some JSON parser.
"\xe2\x80\xa8" => '\u2028', // U+2028, Line Separator.
"\xe2\x80\xa9" => '\u2029', // U+2029, Paragraph Separator.
);

return '"'. strtr($var, $replace_pairs) .'"';

Thanks a lot jp_rajan!

Fixed my issue!

thanks @jp_rajanfor - I had the same issue with views 6.x-2.12 and your solution fixed it. Can you submit a patch or shall I?

is this function present in the D7 version?

Version:6.x-2.x-dev» 6.x-3.0
Priority:Normal» Critical
Status:Needs work» Reviewed & tested by the community

Works for me, aside from the fact that core still doesn't contain the patch mentioned in #1086098: D6 JSON is total garbage - Create RFC 4627 compliant HTML safe JSON which is a related to the issue, but can't be part of this issue's resolution really.

Marking this as critical since it exists in a stable release of views 6.x-3.0 and it breaks the normal operation of the ajax pager.

Hi

I had the same symptoms.
I also found out that this is related to certain characters, as described in #15.

The instructions in #16 solved the problem.
Thank you!

Is there a way to prevent the storing of problematic characters in the first place?
With transliteration or the ckeditor module?

Status:Reviewed & tested by the community» Needs work

The last submitted patch, ajax.error_.handle.patch, failed testing.

I'm using the Secure Pages module and was facing the same problem. wwwpro's solution in #14 fixed it!

Version:6.x-3.0» 6.x-2.12
Status:Needs work» Fixed

On Drupal 6.19, got this error after upgrading jQuery from version 1.3.2 to 1.7.1.
Found out that the bug was with drupal_json function under include/common.inc. Solution #3 fixed it. Thanks to kratkar.
Note that the drupal_set_header('Content-Type: text/javascript; charset=utf-8'); is commented only, notifying the client that the returned content is of json type is not necessary in my case.

See also comment An HTTP error 200 occurred...#46

Status:Fixed» Closed (fixed)
Issue tags:-views, -Ajax, -pager, -Drupal.Views.Ajax.handleErrors

Automatically closed -- issue fixed for 2 weeks with no activity.