Comments not saving

Jul 1, 2009 at 10:17 PM

Howdy,

Check out my blog, www.delphi-ts.com/blogs/lozzi and try leaving a comment. I checked out http://blogengine.codeplex.com/WorkItem/View.aspx?WorkItemId=9116 and the parent web.config doesn't have that value in it. What can I do?

Thanks,

Jul 4, 2009 at 7:04 AM

David,

Tried debugging javascript? Try debugging blog.js file, addComment function in that file.

:Ajay Matharu

http://www.ajaymatharu.com

http://twitter.com/matharuajay

Jul 6, 2009 at 1:49 PM

Using FireFox Error Console, I didn't see any javascript errors popup.

How does one effectively debug javascript code?

Coordinator
Jul 6, 2009 at 11:45 PM

David, there is an error coming back from the server.  It's not a JavaScript error.  It says:

eThere was an error in the callback.

This shows up in Fiddler, and probably Firebug too.  As was suggested in that other thread you pointed to, I would turn off Custom Errors to get a better idea of what's going on.  In your web.config file, change the <customErrors> tag to:

<customErrors mode="Off">

Then when trying to post a comment, there should hopefully be a more detailed error message coming back from the server.  It may require Fiddler to see the error message.  If you don't already have that installed, I or someone else can try posting a comment on your blog again once you've made the custom errors change in your web.config file.

Jul 7, 2009 at 6:35 AM

To debug javascript, you can either debug javascript in Firebug, or you can use alert method by placing alert at various places or if you using VS 2008 you can place breakpoint in javascript and have that hit directly.

 

Aug 19, 2009 at 10:04 PM

I've set customErrors to Off. Any assistance is greatly appreciated!

Aug 19, 2009 at 10:17 PM

I downloaded fiddler and checked it out, i'm not seeing any errors... then again I'm not sure what I'm looking for. The stream output shows results of 200 or 301 for everything, nothing over 400... Do you still see errors BenAmada?

Aug 20, 2009 at 8:25 PM

Fixed it!!! Read post http://blogengine.codeplex.com/Thread/View.aspx?ThreadId=59277.

Jan 2, 2010 at 4:06 AM

BlogEngine 1.5.7. 

Adding comments doesn't work on my hosting web server, but works on my local IIS.

The javascript error I get is line 59 on blog.js:  'BlogEngine.comments.nameBox.value' is null or not an object

Message: 'BlogEngine.comments.nameBox.value' is null or not an object

 

var author = BlogEngine.comments.nameBox.value;

Any clues? 

Thanks in advance.

Coordinator
Jan 2, 2010 at 4:12 AM

When you're on the page leaving a comment, if you do a View Source, you should find some JavaScript towards the bottom that looks like:

function registerCommentBox(){
	BlogEngine.comments.flagImage = BlogEngine.$("ctl00_cphBody_CommentView1_imgFlag");
	BlogEngine.comments.contentBox = BlogEngine.$("ctl00_cphBody_CommentView1_txtContent");
	BlogEngine.comments.moderation = false;
	BlogEngine.comments.checkName = false;
	BlogEngine.comments.postAuthor = "Admin";
	BlogEngine.comments.nameBox = BlogEngine.$("txtName633979804483408203");
	BlogEngine.comments.emailBox = BlogEngine.$("ctl00_cphBody_CommentView1_txtEmail");
	BlogEngine.comments.websiteBox = BlogEngine.$("ctl00_cphBody_CommentView1_txtWebsite");
	BlogEngine.comments.countryDropDown = BlogEngine.$("ctl00_cphBody_CommentView1_ddlCountry"); 
	BlogEngine.comments.captchaField = BlogEngine.$('ctl00_cphBody_CommentView1_hfCaptcha');
	BlogEngine.comments.controlId = 'ctl00$cphBody$CommentView1';
	BlogEngine.comments.replyToId = BlogEngine.$("ctl00_cphBody_CommentView1_hiddenReplyTo"); 
}

Can you find JavaScript similar to this when doing a View Source?  Maybe it's there on your local machine, but not the hosting web server?

Jan 2, 2010 at 4:21 AM

Wow, quick response, thanks Ben. 

Yes, I can see the registerCommentBox() function in a script block on the page in View Source, in IE, and with the Standard theme. When I hit the Save Comment button, I get the "Error on page" exclamation in the status bar, reporting:

 

Message: 'BlogEngine' is undefined
Line: 458
Char: 9
Code: 0
URI: http://www.spacefold.com/colin/blog/WebResource.axd?d=WPlOuL4rgyNDaPA-Suv_j8oz_UZDxvllDUDv5wL3hHQ1&t=633976965805227500

This is interesting because it seems to be a different error than when I used my normal theme. I don't want to complicate things, so 'll stick to debugging the standard theme for now. (My normal theme was moved from 1.4.5, but everything else should be as-is from the 1.5 installation).

 

 

 

Coordinator
Jan 2, 2010 at 4:39 AM

You might be using an old blog.js file (root of your blog).  Before BE version 1.5, there was no "BlogEngine" namespace in the blog.js file.  The blog.js file starting from BE 1.5 defines a "BlogEngine" namespace.  So I would double check and make sure your blog.js file is one from version 1.5.  The first few lines in the version 1.5 blog.js define this namespace ...

// global object
BlogEngine = {
    $: function(id) {
        return document.getElementById(id);
    }

Jan 2, 2010 at 4:45 AM

Yup, it is definitely there. I refreshed the blog.js on the server just to make sure. In IE I see the error exclamation as soon as I tab from the "name" textbox to the "email" textbox.

Coordinator
Jan 2, 2010 at 4:58 AM

It sounds like the Name textbox is misnamed.  The validation checks to make sure the Name is filled in when leaving the tab.  If you do a View Source, look for where the Name is entered.  The HTML source will look something like:

<label for="ctl00_cphBody_CommentView1_txtName">Name*</label>
<input name="ctl00$cphBody$CommentView1$txtName" type="text" value="Ben" id="ctl00_cphBody_CommentView1_txtName" tabindex="2" /><span id="ctl00_cphBody_CommentView1_CustomValidator1" style="color:Red;display:none;">Please choose another name</span><span id="ctl00_cphBody_CommentView1_RequiredFieldValidator1" style="color:Red;display:none;">Required</span><br />

The ID of the INPUT field in this case is "ctl00_cphBody_CommentView1_txtName".  This should match what's in the registerCommentBox() JavaScript function ...

 

BlogEngine.comments.nameBox = BlogEngine.$("ctl00_cphBody_CommentView1_txtName");

 

You can see that ctl00_cphBody_CommentView1_txtName is the ID of the <input>, and it also inside the JavaScript code too.  I'm guessing yours doesn't match?

Jan 2, 2010 at 5:15 AM

Back to the View Source... in the register function it is:

	BlogEngine.comments.nameBox = BlogEngine.$("ctl00_cphBody_CommentView1_txtName633979878909531250");

And earlier, in the actual HTML code:

 

	  <input name="ctl00$cphBody$CommentView1$txtName633979878909531250" type="text" id="ctl00_cphBody_CommentView1_txtName633979878909531250" tabindex="2" />

Based on the ID value, this would be a match, surely?

 

Coordinator
Jan 2, 2010 at 5:48 AM

Yes, you're right, the IDs match.

I should have just gone to your blog ... didn't see the URL at first.  The problem is that blog.js isn't getting loaded.  The blog.js file gets loaded thru the JS handler (JS.axd).  The URL in the <script> tag is:

http://www.spacefold.com/colin/blog/js.axd?path=%2fcolin%2fblog%2fblog.js&v=1.5.0.7

But an empty response is coming back.  But the blog.js file does exist ... when I try to manually navigate to it:

http://www.spacefold.com/colin/blog/blog.js

I'm not sure right now why the JavaScript handler (js.axd) is returning a blank document.  One cheap workaround is to manually add a script tag into your site.master file, in the HEAD section.

<script src="http://www.spacefold.com/colin/blog/blog.js" type="text/javascript"></script>

Maybe Read permissions for the ASPNET account aren't setup for the root folder.  Typically that's not the case.  For one person, I think JS.axd wasn't working until the removed the first line in blog.js:

// global object

That JavaScript comment beginning with two slashes was causing one person problems.  When they removed the comment, it started working.  Not sure if that's the same problem here.

Maybe something else will pop in my mind... hopefully.

Coordinator
Jan 2, 2010 at 5:55 AM

The JavaScript handler keeps the content of blog.js stored in cache -- so it doesn't need to keep re-reading the blog.js file.  It's possible the first time it read it, it didn't get any content from the file (for some reason).  And then it cached a blank string in memory.  And now it's just passing that blank string back out.

I would try restarting your blog to clear out whatever's in cache.  You can restart it by making any change to the web.config file, for example.  After restarting it, try accessing the URL which is currently returning a blank document:

http://www.spacefold.com/colin/blog/js.axd?path=%2fcolin%2fblog%2fblog.js&v=1.5.0.7

It might start returning some actual content after the application restart.

Jan 2, 2010 at 6:24 AM

Interesting test... ok, I changed the web.config and restarted the blog app (took a while to load).

That URL returned.... a blank page.

So I did the edit:

 

// global object

to:

 

 

global object

 

and then re-uploaded blog.js and web.config (to reset the cache). Now the URL seems to return the contents of blog.js (in firefox I see it in the browser window). 

But now there is also an error on the home page of the blog:

 

Message: Expected ';'
Line: 1
Char: 8
Code: 0
URI: http://www.spacefold.com/colin/blog/js.axd?path=%2fcolin%2fblog%2fblog.js&v=1.5.0.7

Here's the thing - the comments were working fine on my local IIS webserver, - but I'm sure I refreshed all the files on the web host server.

Coordinator
Jan 2, 2010 at 6:27 AM

Sorry, if you remove the 2 slashes, then you need to remove the entire line.  So don't leave "global object" by itself .... delete that too (IOW delete the entire first line)

Jan 2, 2010 at 6:31 AM

OK, sorry about that. I've deleted the entire line, and uploaded blog.js (and web.config for the cache reset). It does not appear to have made any difference.
I still get the expected ';' javascript error on the home page.

Coordinator
Jan 2, 2010 at 6:36 AM

I think it is working now... I just left a comment.

You might have the old JavaScript file cached in your browser.  When you get to the site, do a no-cache refresh (Ctrl-F5).  This will reload everything and clear out any old cached items like the JavaScript file.

Jan 2, 2010 at 6:43 AM

That is awesome. Thank you Ben. Now that you've got this working, I'll have a baseline to compare my custom theme with, if it turns out to have a problem.

May 21, 2010 at 5:05 AM

hi,

 

I am facing the same problem when I used other theme rather than standard i.e Eco theme.  I have used all the steps given by above but still it's not working and giving a error.  Can anybody help me on this?