Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#9 | ajax.error_.handle.patch | 2.34 KB | kratkar |
#5 | ajax_view.zip | 2.73 KB | kratkar |
Comments
Comment #1
kratkar CreditAttribution: kratkar commentedAdd 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)))
Comment #2
BassEast CreditAttribution: BassEast commentedI 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?
Comment #3
kratkar CreditAttribution: kratkar commentednot 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
to a new
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))
Comment #4
BassEast CreditAttribution: BassEast commentedWhat 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?
Comment #5
kratkar CreditAttribution: kratkar commentedfile : /sites/all/modules/views/js/ajax.js line 334:
add in file sites/all/modules/views/js/ajax_view.js
Look for attachment.)
Comment #6
BassEast CreditAttribution: BassEast commentedSo, the error in alert is: "parsererror" :) now what?))
Comment #7
kratkar CreditAttribution: kratkar commented/incudes/common.php line 2499 (function drupal_to_js)...
more here: http://drupal.org/node/914360#comment-3468550 ))
Comment #8
BassEast CreditAttribution: BassEast commentedКарен, спасибо огромное! Помогло :) жаль только системный модуль затрагивается..
Comment #9
kratkar CreditAttribution: kratkar commentedМне за что))
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
Comment #10
kratkar CreditAttribution: kratkar commentedComment #11
merzikain CreditAttribution: merzikain commentedI had the same problem and this solution helped.
Thanks!
Comment #12
dawehnerCould you use drupal code style? Thanks!
Comment #13
mghatiya CreditAttribution: mghatiya commentedWon't it be simpler to just include the ajax.js file too? Am I missing something?
Comment #14
wwwpro CreditAttribution: wwwpro commentedI 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.
Comment #15
brad.bulger CreditAttribution: brad.bulger commentedrelated 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
Comment #16
jp_rajan CreditAttribution: jp_rajan commentedi 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) .'"';
Comment #17
zeno.popovici CreditAttribution: zeno.popovici commentedThanks a lot jp_rajan!
Fixed my issue!
Comment #18
klokie CreditAttribution: klokie commentedthanks @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?
Comment #19
dreadlocks1221 CreditAttribution: dreadlocks1221 commentedis this function present in the D7 version?
Comment #20
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedWorks 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.
Comment #21
stefan81 CreditAttribution: stefan81 commentedHi
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?
Comment #23
landing CreditAttribution: landing commentedI'm using the Secure Pages module and was facing the same problem. wwwpro's solution in #14 fixed it!
Comment #24
ahpoonja CreditAttribution: ahpoonja commentedOn 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
Comment #27
geosalameh CreditAttribution: geosalameh commentedSolution #3 fixed it. Thanks to kratkar.