Submitting a comment causes redirect
| Project: | Ajax |
| Version: | 6.x-1.12 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | brendoncrawford |
| Status: | active |
I have installed the ajax module, the ajax plugin - comment module, and the ajax ui module, and have enabled ajax handling for the comment form via the settings page. When I submit my comment an ajax request is made:
comment=this+is+a+test&format=1&form_build_id=form-c190f689cb1eb7b88bf5c53d120dea3e&form_token=92664e95bb67a1344aff9ed1d1d6b98d&form_id=comment_form&op=Preview&drupal_ajax=1and I get a response back:
{ "status": true, "updaters": [ ], "debug": [ ], "messages_error": [ ], "messages_status": [ ], "messages_warning": [ ], "redirect": "http://redacted.com/groups/1999/pagename#comment-45", "preview": null }But nothing on the user interface changes. I am not redirected nor do i see an alert or a change in content. If I leave the form blank, I am redirected to the same page with an error notice.
If I click preview instead, I get more meaningful data back:
{ "status": true, "updaters": [ ], "debug": [ ], "messages_error": [ ], "messages_status": [ ], "messages_warning": [ ], "redirect": null, "preview": "\x3cdiv class=\"preview\"\x3e\x3ca id=\"new\"\x3e\x3c/a\x3e\n\x3ca id=\"comment-\"\x3e\x3c/a\x3e\n\x3cdiv class=\"comment comment-new comment-preview odd first comment-mine\"\x3e\x3cdiv class=\"comment-inner clear-block\"\x3e\n\n \x3cdiv class=\"new\"\x3enew\x3c/div\x3e\n \n \n \n \x3cdiv class=\"submitted\"\x3e\n POSTED BY \x3ca href=\"/groups/1999/pagename#admin\"\x3eUSERNAME\x3c/a\x3e \x3ca href=\"/groups/1999\"\x3e\'99\x3c/a\x3e \x3c/div\x3e\n\n \x3cdiv class=\"content\"\x3e\n \x3cp\x3ethis is a test\x3c/p\x3e\n \x3c/div\x3e\n\n \n\x3c/div\x3e\x3c/div\x3e \x3c!-- /comment-inner, /comment --\x3e\n\x3c/div\x3e" }And the page is updated with this preview HTML. Submitting does nothing though.
If I try the dev version, everything is the same except after clicking Submit the AJAX request returns the same data and then redirects to the "redirect" url given in the return data.
I tried this with my theme and a default theme (Garland). I am using Drupal 6.9.
I have also tried the plugin that prevents redirect, in the dev branch, and the form still redirected.
Can anyone assist?

#1
Matteusx,
Thanks for your feedback.
Can you post the json response that you get with 6.x-1.x-dev?
Thanks,
Brendon
#2
subscribe, having the same problem here..
Btw, how do u debug json response ??
#3
You can see the json response from the Firebug console in FireFox. This would be greatly helpful to see.
Thanks
#4
I'm getting a similar error as described by the OP. However, my problem only occurs in IE. Firefox works as desired.
Two of the runtime errors that IE is throwing on loading a page(not submitting the form) relate to the same line in ajax_disable_redirect.js:
Drupal.Ajax.plugins.disable_redirect = function(hook, args) {The other error refers to a line in ajax_views_refresh.js:
Drupal.Ajax.plugins.ajax_views_refresh = function(hook, args) {The errors being thrown by the browser are:
Error 1
Line 136Error: Expected Identifier, string or number
Error 2
Line: 23Error: 'Drupal.Ajax.plugins' is null or not an object.
The debugger is pointing to the same line as mentioned in error 1 even though the pop-up window referred to a different line number.
Error 3
Error: 'Drupal.Ajax.plugins' is null or not an object.however this time it refers to a line in ajax_views_refresh.js and not ajax_disable_redirect.js.
When submitting the form it redirect to MYSITEURL.COM/comment/reply/ and on that page the following HTML source is being displayed:
<textarea>{ "status": true, "updaters": [ ], "debug": [ ], "messages_error": [ ], "messages_status": [ { "id": 0, "value": "User \x3cem\x3econor\x3c/em\x3e \x3cem\x3eearned\x3c/em\x3e \x3cem\x3e2\x3c/em\x3e cookies Total now is \x3cem\x3e448\x3c/em\x3e cookies." } ], "messages_warning": [ ], "redirect": "http://MYSITEURL/node/67?page=2\x261857218348=1", "preview": null, "form_id": "comment_form", "options": { "enabled": true, "disable_redirect": true, "remove_form": false, "views_refresh": true } }</textarea>#5
Phonedream2,
Does your comment form have a file upload in it?
#6
No, my comment doesn't have a file upload in it. It does have the functionality of the Riffly module. I disabled the Riffly module, but it didn't solve the issue.
Do you suspect a conflict with an existing module?
I disabled the views_refresh and disable_redirect modules and the error I'm getting is now from ajax.js. The Microsoft Script Debugger is pointing to the line that reads:
if (Drupal.Ajax.invoke('message', data)) {I'm not sure how accurate the MS Script Debugger is.
#7
To isolate the problem I used the following code in ajax_disable_redirect.js on line 1.
alert(Drupal);The purpose of this code is to see what type 'Drupal' has. On viewing the webpage an alert box pops up as expected with the text 'Object'.
I then tried the following code:
alert(Drupal.Ajax);The pop-up box then had the text 'undefined'.
#8
Can you try it in Firefox and post the Firebug error?
#9
It works in Firefox, just not in IE.
I'll try Firefox when I get home tonight and see what value it gives for Drupal.Ajax.
EDIT: Just got home. Interesting, Firefox gives an 'Object' definition, whereas IE has it as 'undefined'. So, for some reason the Drupal.Ajax property (object?) is defined in Firefox but not IE.
#10
The 'Drupal' object has different properties in Firefox than in IE. In Firefox there is a property, Ajax, which is in itself an object. This object doesn't exist in IE.
However, IE contains some properties that IE doesn't, namely 'jsAC' and 'ACDB'.
Using the following code to initialize the DrupalAjax object (for IE) in ajax_disable_redirect.js makes the error go away:
var Ajax = Drupal.Ajax || { 'plugins': {}, 'firstRun': {}, 'init': {}, 'invoke': {}, 'go': {}, 'message':{}, 'writeMessage':{}, 'updater':{}, 'response':{}, 'redirect':{} };Drupal.Ajax = Ajax;
Unfortunately this doesn't remedy the faulty behavior in IE - the page is still redirecting as outlined above in the bottom of post #4:
In addition, there is now a different error in Ajax.js being presented in IE:
Line: 137Error, unexpected identifier, string or number
with the script debugger pointing to the following piece of code:
if (Drupal.Ajax.invoke('message', data)) {I'm wary of the accuracy of the script debugger as I commented out the IF block and it was still pointing to it.
#11
Phonydream,
Thanks that is actually quite helpful. I just fixed the IE error on line 137. Please download latest dev which should update within 12 hours. I think with some collaboration here we can get this thing knocked out.
#12
I've just updated the module to the May 22nd 6.x-1.x-dev release.
The desired functionality now works intermittently in IE. Unfortunately, upon pressing the forms submit button it occasionally hangs and the text 'Loading...' appears without any changes being made. I haven't been able to reproduce this problem with Firefox. This might be a networking issue and not due to the limitations of the module.
IE is no longer throwing any script errors.
Update: I've just added 20 new comments without any problems in IE. The problem of the form hanging occurred twice (within the space of two submits) after I installed the 6.x-1.x-dev release.
I'll do more testing, but it looks VERY promising! Nice work, thanks so much!
#13
I am having what seems to be the same issue.
I'm on Drupal 6.10, latest ajax dev module as of today (May 26). I have the following modules enabled: Ajax, Comment, Disable Redirect, Logintoboggan, Scroller, Views_Refresh, and Ajax UI. The settings for the comment form are currently set to "Enabled" and "Disable Redirect".
What I am trying to accomplish is having the comment box on a node be AJAXed for both submission and update. The use case is a user is viewing the node (which has an embedded flash video playing), the user submits a comment, and the submission is posted without a refresh. This is the current behavior, however with "Disable Redirect" the new comment will not appear without the user refreshing the page. This is my problem - I would like the new comment to show up right away, similar to what happens when you click Preview. The comment is accepted just fine and does appear on node refresh. If I turn off "Disable Redirect", the comment is accepted but the page is reloaded which restarts the video.
Is this possible or is it working as intended?
Thanks in advance both to your development efforts AND for spending so much time in the issue queue reading and replying!
FWIW - I tested in Garland and here is the Firebug output.
Post:
comment second Garland test
drupal_ajax 1
form_build_id form-e6f9bdcb0b950f8eb3e0e123678defae
form_id comment_form
form_token fd0342e67b244660f0ef261d1a510058
op Save
Response:
{ "status": true, "updaters": [ ], "debug": [ ], "messages_error": [ ], "messages_status": [ ], "messages_warning"
: [ ], "redirect": "http://myserver.mydomain.com/file/myfilename?2094873012=1", "preview"
: null, "form_id": "comment_form", "options": { "enabled": true, "disable_redirect": true, "remove_form"
: false, "scroller": false, "views_refresh": false } }
JSON:
debug []
form_id "comment_form"
messages_error []
messages_status []
messages_warning []
options Object enabled=true disable_redirect=true
disable_redirect true
enabled true
remove_form false
scroller false
views_refresh false
preview null
redirect "http://myserver.mydomain.com/file/myfilename?2094873012=1"
status true
updaters []
#14
Are your comments being displayed as a view? If so, you should enable views_refresh for comments at www.YOURSITEURL/admin/settings/ajax. Your Firebug output indicates that views_refresh is disabled.
I have similar functionality on my site (video can be played, comments submitted) however I'm displaying the comments as a view.
#15
In this case, my comments are not a view - this was part of a straight rendering of a node. Perhaps I should migrate to displaying comments as a block view at the bottom and trying it that way. I'll give that a shot, thanks.
#16
I am also having this problem (have updated to the May 28 dev release and the problem persists) - was anyone able to solve it?
The preview button works as desired, but the submit does not alter the content of the page. If the page is reloaded, the comment is there.
Behavior is the same in both Firefox and IE.
#17
Using Firebug to see the post and response, this is how things look:
POST
comment okay. another test comment.drupal_ajax 1
form_build_id form-487fb71787f2ce096bf6a0b1f09a123f
form_id comment_form
form_token c1e3cddea2e84dfda54c6e6dd9d329cf
format 1
op Save
RESPONSE
{"status": true,
"updaters": [ ],
"debug": [ ],
"messages_error": [ ],
"messages_status": [ ],
"messages_warning": [ ],
"redirect": "http://mysite.com/node/19?875278191=1",
"preview": null,
"form_id": "comment_form",
"options": {
"enabled": true,
"disable_redirect": true,
"remove_form": false,
"scroller": false
}
}
JSON output attached