Posted by BassEast on September 17, 2010 at 6:47am
14 followers
| Project: | Views |
| Version: | 6.x-3.0 |
| Component: | Views Data |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs work |
| Issue tags: | Ajax, Drupal.Views.Ajax.handleErrors, pager, views |
Issue Summary
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.
Comments
#1
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)))
#2
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?
#3
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))
#4
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?
#5
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 < 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}));
}
add in file sites/all/modules/views/js/ajax_view.js
Look for attachment.)
#6
So, the error in alert is: "parsererror" :) now what?))
#7
/incudes/common.php line 2499 (function drupal_to_js)...
more here: http://drupal.org/node/914360#comment-3468550 ))
#8
Карен, спасибо огромное! Помогло :) жаль только системный модуль затрагивается..
#9
Мне за что))
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
#10
#11
I had the same problem and this solution helped.
Thanks!
#12
+ 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!
#13
Won't it be simpler to just include the ajax.js file too? Am I missing something?
#14
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.
#15
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
#16
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) .'"';
#17
Thanks a lot jp_rajan!
Fixed my issue!
#18
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?
#19
is this function present in the D7 version?
#20
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.
#21
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?
#22
The last submitted patch, ajax.error_.handle.patch, failed testing.