I'm starting to get into jQuery only as I need on my site that a person write an opinion and it appears right below without having to refresh the page. wanted a person to enter anything in the database given that this content appears on the page without having to update.
I need some lights on how to do this.
Code that I'm using
JS
$(function () {
$(".submit_button").click(function () {
var textcontent = $("#comentario").val();
var dataString = 'id_estabelecimento=<?php echo $row->id; ?>&user_id=<?php echo $_SESSION['
user_id '] ?>&opiniao=' + textcontent;
if (textcontent == '') {
alert("Por favor escreva um comentário..");
$("#comentario").focus();
} else {
$("#flash").show();
$("#flash").fadeIn(400).html('<span class="load">Aguarde por favor..</span>');
$.ajax({
type: "POST",
url: "ajax/adicionar_comentario.php",
data: dataString,
cache: true,
success: function (html) {
$("#show").after(html);
document.getElementById('comentario').value = '';
$("#flash").hide();
$("#comentario").focus();
}
});
}
return false;
});
});
HTML
<form method="post" name="form" action="">
<input type="hidden" name="valida" id="valida" value="ok" />
<table border="0" bgcolor="#E9EAED" style="margin:0px 0px 30px 0px;" width="100%" cellpadding="0" cellspacing="0">
<?php if($_SESSION[ 'FBID'] || $_SESSION[ 'user_id']){ ?>
<tr>
<td valign="top">
<div id="flash" align="left"></div>
<div id="show" align="left"></div>
</td>
</tr>
<tr>
<td valign="top" width="7%">
<div style="padding:15px 5px 5px 20px;">
<img width="33" height="33" src="<?php echo $_SESSION['user_foto'] ?>" />
</div>
</td>
<td valign="top" width="93%">
<div style="padding:15px 20px 15px 5px;">
<input type="text" style="width:100%; height:33px;" placeholder="Escreve um comentário..." id="comentario" name="comentario" value="">
</div>
<input type="submit" id="submit" style="display:none;" class="submit_button">
</td>
</tr>
php code of file adiconar_comentario.php
session_start();
require_once("../gtm/bd/funcoes.php");
ligarBd();
mysql_query("INSERT INTO comentarios (user_id, post_id, comentario, data) VALUES('".$_REQUEST['user_id']."', '".$_REQUEST['id_estabelecimento']."', '".$_REQUEST['opiniao']."', now())");