Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Ajax commenting with prototype  (Read 9641 times)

Vasile Rusnac

  • Newbie
  • *
  • Karma: 7
  • Posts: 49
Ajax commenting with prototype
« on: September 23, 2007, 10:28:40 PM »

These days I have been trying to to change the //comments function to include an Ajax features that makes adding comments process not reloading the whole page.
for this I have used a simple script that I have placed after the form:
Code: [Select]
<script>
function addcomment()
{
  new Ajax.Updater( 'comments', 'snews.php',
{
method: 'post',
parameters: $('post').serialize(),
onSuccess: function() {
$('text').value = '';
}
} );
}
</script>
where:
"comments" - is the div id where the comments will appear
"snews.php" - the file that processes the comment function
"post" - the id of the form
"text" - the id of the textarea.

then I substituted the submit button:
instead of
Code: [Select]
echo html_input('submit', 'comment', 'comment', l('submit'), '', 'button', '', '', '', '', '', '', '', '', '');I inserted
Code: [Select]
<button onclick="addcomment()">Add Comment</button>And added prototype.js file

as you might presume, I do not get any results :) I succeed to send the form, as it might be seen, but data are not inserted into the database.

Will appreciate any help on creating this hack to Ajaxify the comment function. 8)
Logged

centered

  • Guest
Re: Ajax commenting with prototype
« Reply #1 on: September 24, 2007, 02:49:33 AM »

Prototype seems to break the toggle button of sNews... Not confirmed but it happens to me with 1.6...
Logged

jared351

  • Sr. Member
  • ****
  • Karma: 4
  • Posts: 276
Re: Ajax commenting with prototype
« Reply #2 on: September 24, 2007, 07:17:11 AM »

It has also happened to me too. I would personally suggest mootools, it seems to work okay. Very good idea!
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: Ajax commenting with prototype
« Reply #3 on: September 24, 2007, 09:01:11 AM »

and, I say it again, there's Ahah too... ;D

Vasile Rusnac

  • Newbie
  • *
  • Karma: 7
  • Posts: 49
Re: Ajax commenting with prototype
« Reply #4 on: September 24, 2007, 09:36:48 AM »

Prototype seems to break the toggle button of sNews... Not confirmed but it happens to me with 1.6...
Yes it does, because prototype already defines the toggle function:
Code: [Select]
  toggle: function(element) {
    element = $(element);
    Element[Element.visible(element) ? 'hide' : 'show'](element);
    return element;
  },
so it messes with the original snews toggle function. but that is not grave as you can always remove the toggle function from prototype.
Logged

jared351

  • Sr. Member
  • ****
  • Karma: 4
  • Posts: 276
Re: Ajax commenting with prototype
« Reply #5 on: September 24, 2007, 06:33:11 PM »

Yah that is true.
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Re: Ajax commenting with prototype
« Reply #6 on: September 25, 2007, 03:01:02 AM »

Or you could simply rename the toggle function within sNews to something like snews_toggle no?
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

jared351

  • Sr. Member
  • ****
  • Karma: 4
  • Posts: 276
Re: Ajax commenting with prototype
« Reply #7 on: September 25, 2007, 04:53:24 AM »

Good thought, but wouldn't the functions still interfere with each other?
Logged

centered

  • Guest
Re: Ajax commenting with prototype
« Reply #8 on: September 25, 2007, 01:08:30 PM »

No it wouldn't.  Good idea Pixelated, didn't think of that one..
Logged

ens

  • Sr. Member
  • ****
  • Karma: 12
  • Posts: 279
    • http://www.meatysite.info
Re: Ajax commenting with prototype
« Reply #9 on: September 25, 2007, 01:34:40 PM »

I tried this myself a while back. I think I found out that it wouldn't work because of something to do with the way snews handles rewrites and how pages... anyway I'm not exactly sure, but it's got to do with snews being a one-file system, you know?
Logged

Vasile Rusnac

  • Newbie
  • *
  • Karma: 7
  • Posts: 49
Re: Ajax commenting with prototype
« Reply #10 on: September 25, 2007, 03:59:57 PM »

I tried this myself a while back. I think I found out that it wouldn't work because of something to do with the way snews handles rewrites and how pages... anyway I'm not exactly sure, but it's got to do with snews being a one-file system, you know?
So you think it wont work? mmm, not good news :(
anyway, what if we take apart the comment function and insert in in a separate file, lets say submitcomments.php
is there any hope?  ;)
Logged

Joost

  • Guest
Re: Ajax commenting with prototype
« Reply #11 on: September 25, 2007, 04:16:26 PM »

I tried this myself a while back. I think I found out that it wouldn't work because of something to do with the way snews handles rewrites and how pages... anyway I'm not exactly sure, but it's got to do with snews being a one-file system, you know?
So you think it wont work? mmm, not good news :(
anyway, what if we take apart the comment function and insert in in a separate file, lets say submitcomments.php
is there any hope?  ;)
Javascript is executed client-side so it is only effected by the environment on the client. It cannot be effected by the amount of files server-side.
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Re: Ajax commenting with prototype
« Reply #12 on: September 25, 2007, 06:36:38 PM »

I tried this myself a while back. I think I found out that it wouldn't work because of something to do with the way snews handles rewrites and how pages... anyway I'm not exactly sure, but it's got to do with snews being a one-file system, you know?
So you think it wont work? mmm, not good news :(
anyway, what if we take apart the comment function and insert in in a separate file, lets say submitcomments.php
is there any hope?  ;)
Vasile ... it's doable and might be even easier to do with separate file IMHO but that doesn't mean You can't do it by squeezing everything into single file, never mind rewrites, client sides and all ;) Still easier would be to handle ajaxed piece of output in separate file :D
Logged

Vasile Rusnac

  • Newbie
  • *
  • Karma: 7
  • Posts: 49
Re: Ajax commenting with prototype
« Reply #13 on: September 25, 2007, 09:11:35 PM »

codetwist, well, I also didnt thought the one-file cms would be a problem or the rewrite thing, still, something is escaping from me.
I was experimenting and I managed to take a simple comment system and "ajaxify" it, everything works fine (well, with some minor bugs and the fact that it doesnt show at all in IE6 :-\)
and I do exactly the same with snews and it still doesnt work.
maybe, indeed, I should try mootols and quit on prototype.
Logged

jared351

  • Sr. Member
  • ****
  • Karma: 4
  • Posts: 276
Re: Ajax commenting with prototype
« Reply #14 on: September 25, 2007, 09:20:36 PM »

Well to be honest, I used mootools on sites with snews and it worked seamlessly..and mootools has tons of different java functions to choose from..Cheers!
Logged
Pages: [1] 2