[jQuery] jquery.form not working (comment system using jquery)
Im trying to integrate a comment system using jquery into my project
but it doesn't work I need some help finding where the error could be:
javascript:
<script type="text/javascript">
$(document).ready(function() {
jQuery('#newComment').after('<div id="error"></div>');
jQuery('#submit').after('<img src="http://192.168.0.5/flog/
loading.gif" id="loading" alt="loading..." />');
jQuery('#loading').hide();
var form = jQuery('#newComment');
var err = jQuery('#error');
var error = "error";
form.submit(function(evt) {
if(form.find('#author')[0]) {
if(form.find('#author').val() == '') {
err.html('<span class="error">Enter Name</span>');
return false;
} // end if
if(form.find('#comment').val() == '') {
err.html('<span class="error">Enter Comment</span>');
return false;
} // end if
jQuery(this).ajaxSubmit({
beforeSubmit: function() {
jQuery('#loading').show();
jQuery('#submit').attr('disabled','disabled');
}, // end beforeSubmit
error: function(request){
err.empty();
var data = request.responseText;
err.html('<span class="error">'+ data[1] +'</span>');
jQuery('#loading').hide();
jQuery('#submit').removeAttr("disabled");
return false;
}, // end error()
success: function(data) {
try {
var response = jQuery("<ol>").html(data);
if (jQuery(document).find('.commentlist')[0]) {
jQuery('.commentlist').append(response.find('.commentlist
li:last'));
} else {
jQuery('#respond').before(response.find('.commentlist'));
} // end if
if (jQuery(document).find('#comments')[0]) {
jQuery('#comments').html(response.find('#comments'));
} else {
jQuery('.commentlist').before(response.find('#comments'));
} // end if
err.empty();
form.remove(); // REMOVE THIS IF YOU DON'T WANT THE FORM TO
DISAPPEAR
jQuery('#respond').hide();
err.html('<span class="success">Your comment has been added.</
span>');
jQuery('#submit').removeAttr("disabled");
jQuery('#loading').hide();
} catch (e) {
jQuery('#loading').hide();
jQuery('#submit').removeAttr("disabled");
alert(error+'\n\n'+e);
} // end try
} // end success()
}); // end ajaxSubmit()
return false;
}); // end form.submit()
}); // end document.ready()
</script>
my form:
<form id="newComment" action="http://192.168.0.5/flog/add.php"
method="post">
Nombre <br />
<input name="author" type="text" class="texto" id="author"
size="30" />
<br />Mensaje:<br />
<textarea name="comment" id="comment" cols="40" rows="8"
class="texto" ></textarea>
<br />
<input type="submit" name="submit" id="submit"
class="boton" value="Agregar Comentario →" />
<input type="hidden" name="comment_postid" value="28" />
<input type="hidden" name="type" id="type" value="1" /