¡Hola a todos! tengoTengo este sistema de comentarios pero tarda mucho en cargar ¿ hay. ¿Hay alguna solución? Gracias de antemano. index.php
index.php
¡Hola a todos! tengoTengo este sistema de comentarios pero tarda mucho en cargar ¿ hay. ¿Hay alguna solución? Gracias de antemano. index.php
index.php
¡Hola a todos! tengo este sistema de comentarios pero tarda mucho en cargar ¿ hay alguna solución? Gracias de antemano. index.php
Tengo este sistema de comentarios pero tarda mucho en cargar. ¿Hay alguna solución?
index.php
<link rel="stylesheet" type="text/css" <script>href="bootstrap/css/bootstrap.min.css">
var totalLikes<script =type="text/javascript" 0;src="js/jquery.min.js"></script>
var totalUnlikes =<script 0;src="bootstrap/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<link href="css/estilos.css" functionrel="stylesheet" postReply(commentId)type="text/css" {/>
<script $('#commentId')src="js/jquery-3.val(commentId);
$("#name")2.focus();
1.min.js" }type="text/javascript"></script>
$("#submitButton").click(function () {
$("#comment-message").css('display', 'none');
var str = $("#frm-comment").serialize();
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
$.ajax({ </div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel-body">
<!--Inicio elementos contenedor-->
<div class="comment-form-container">
url: "AgregarComentario.php", <form id="frm-comment">
data:<div str,class="input-row">
type: 'post', <input type="hidden" name="comentario_id" id="commentId"
success: function (response) placeholder="Name" /> <input class="input-field"
{ type="text" name="name" id="name" placeholder="Nombres" />
</div>
var result = eval('(' + response + ')'); <div class="input-row">
if<textarea (response)class="input-field" type="text" name="comment"
{ id="comment" placeholder="Agregar comentario"> </textarea>
</div>
$("#comment <div>
<input type="button" class="btn-message").css('display',submit" 'inlineid="submitButton"
value="Publicar Ahora" /><div id="comment-block'message">Comentario ha sido agregado exitosamente!</div>
</div>
<div style="clear:both"></div>
</form>
</div>
<div id="output"></div>
<script>
var totalLikes = 0;
var totalUnlikes = 0;
function postReply(commentId); {
$('#commentId').val(commentId);
$("#name").valfocus("");
}
$("#comment""#submitButton").valclick(""function (); {
$("#comment-message").css('display', 'none');
var str = $("#commentId""#frm-comment").valserialize("");
$.ajax({
listComment(); url: "AgregarComentario.php",
}data: elsestr,
type: 'post',
success: function (response)
{
var result = eval('(' + response + ')');
if (response)
{
$("#comment-message").css('display', 'inline-block');
$("#name").val("");
$("#comment").val("");
$("#commentId").val("");
listComment();
} else
{
alert("Failed to add comments !");
return false;
}
}
});
});
});
$(document).ready(function () {
listComment();
});
function listComment() {
$.post("ListaDeComentariosdocument).php",
ready(function (data) {
listComment();
var data = JSON.parse(data });
var commentsfunction =listComment() "";{
var replies = "";$.post("ListaDeComentarios.php",
var itemfunction =(data) "";{
var parent = -1;
var resultsdata = new ArrayJSON.parse(data);
var listcomments = $("<ul"";
class='outer-comment'>"); var replies = "";
var item = $("<li>").html"";
var parent = -1;
var results = new Array(comments);
for ( var ilist = 0; $(i <"<ul data.lengthclass='outer-comment'>"); i++)
{
var commentId = data[i]['comentario_id'];
parentitem = data[i]['parent_comentario_id'];$("<li>").html(comments);
var obj =for getLikesUnlikes(commentId);
var i = if0; (parenti ==< "0"data.length); i++)
{
if(data[i]['like_unlike']var >=commentId 1)= data[i]['comentario_id'];
{
parent = data[i]['parent_comentario_id'];
var like_iconobj = "<img src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislikegetLikesUnlikes(" + data[i]['comentario_id'] + ",-1commentId)' />";;
like_icon += "<img style='display:none;' src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
if (parent == else"0")
{
if(data[i]['like_unlike'] >= 1)
{
like_icon = "<img src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img style='display:none;' src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
else
{
like_icon = "<img style='display:none;' src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
}
comments = "\
<div class='comment-row'>\
comments = "\
<div class='comment-row'>\info'>\
<div class='comment-info'>\
<span class='commet-row-label'>De</span>\
<span class='posted-by'>" + data[i]['comment_sender_name'] + "</span>\
<span class='commet-row-label'>a las </span> \
<span class='posted-at'>" + data[i]['date'] + "</span>\
</div>\
<div class='comment-text'>" + data[i]['comment'] + "</div>\
<div>\
<a class='btn-reply' onClick='postReply(" + commentId + ")'>Responder</a>\
</div>\
<div class='post-action'>\ " + like_icon + " \
<span id='likes_" + commentId + "'> " + totalLikes + " Me Gusta </span>\
</div>\
</div>";
var item = $("<li>").html(comments);
list.append(item);
var reply_list = $('<ul>');
item.append(reply_list);
listReplies(commentId, data, reply_list);
}
}
}
$("#output").html(list);
});
}
);
function listReplies(commentId, data, list) {}
for (var i = 0;function listReplies(i <commentId, data.length);, i++list)
{
var obj =for getLikesUnlikes(data[i].comentario_id);
var i = if0; (commentIdi ==< data[i]data.parent_comentario_idlength); i++)
{
if(data[i]['like_unlike'] >= 1)
{
var like_iconobj = "<img src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislikegetLikesUnlikes(" + data[i]['comentario_id'] + ",-1data[i].comentario_id)' />";;
like_icon += "<img style='display:none;' src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike'if onClick='likeOrDislike(" + data[i]['comentario_id']commentId +== ",1data[i].parent_comentario_id)' />";
}
else
{
if(data[i]['like_unlike'] >= 1)
{
like_icon = "<img src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img style='display:none;' src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
else
{
like_icon = "<img style='display:none;' src='img/NoMeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
var comments = "\
<div class='comment-row'>\
<div class='comment-info'>\
<span class='commet-row-label'>De </span>\
<span class='posted-by'>" + data[i]['comment_sender_name'] + "</span>\
<span class='commet-row-label'>a las </span> \
<span class='posted-at'>" + data[i]['date'] + "</span>\
</div>\
<div class='comment-text'>" + data[i]['comment'] + "</div>\
<div>\
<a class='btn-reply' onClick='postReply(" + data[i]['comentario_id'] + ")'>Responder</a>\
</div>\
<div class='post-action'> " + like_icon + " \
<span id='likes_" + data[i]['comentario_id'] + "'> " + totalLikes + " Me Gusta </span>\
</div>\
</div>";
var item = $("<li>").html(comments);
var reply_list = $('<ul>');
list.append(item);
item.append(reply_list);
listReplies(data[i].comentario_id, data, reply_list);
}
}
}
}
function getLikesUnlikes(commentId)
{
$.ajax({
type: 'POST',
async: false,
url: 'Envio_MeGusta.php',
data: {comentario_id: commentId},
success: function (data)
{
totalLikes = data;
}
});
}
function likeOrDislike(comentario_id,like_unlike)
{
$.ajax({
url: 'MeGusta_NoMeGusta.php',
async: false,
type: 'post',
data: {comentario_id:comentario_id,like_unlike:like_unlike},
dataType: 'json',
success: function (data) {
$("#likes_"+comentario_id).text(data + " likes");
if (like_unlike == 1) {
$("#like_" + comentario_id).css("display", "none");
$("#unlike_" + comentario_id).show();
}
if (like_unlike == -1) {
$("#unlike_" + comentario_id).css("display", "none");
$("#like_" + comentario_id).show();
}
},
error: function (data) {
alert("error : " + JSON.stringify(data));
}
},
error: function (data) {
alert("error : " + JSON.stringify(data));
}
});
}
</script>
Agregarcomentario.phpAgregarcomentario.php
Enviomegusta.phpEnviomegusta.php
Listadocomentarios.phpListadocomentarios.php
megusta-nomegusta.phpmegusta-nomegusta.php
<script>
var totalLikes = 0;
var totalUnlikes = 0;
function postReply(commentId) {
$('#commentId').val(commentId);
$("#name").focus();
}
$("#submitButton").click(function () {
$("#comment-message").css('display', 'none');
var str = $("#frm-comment").serialize();
$.ajax({
url: "AgregarComentario.php",
data: str,
type: 'post',
success: function (response)
{
var result = eval('(' + response + ')');
if (response)
{
$("#comment-message").css('display', 'inline-block');
$("#name").val("");
$("#comment").val("");
$("#commentId").val("");
listComment();
} else
{
alert("Failed to add comments !");
return false;
}
}
});
});
$(document).ready(function () {
listComment();
});
function listComment() {
$.post("ListaDeComentarios.php",
function (data) {
var data = JSON.parse(data);
var comments = "";
var replies = "";
var item = "";
var parent = -1;
var results = new Array();
var list = $("<ul class='outer-comment'>");
var item = $("<li>").html(comments);
for (var i = 0; (i < data.length); i++)
{
var commentId = data[i]['comentario_id'];
parent = data[i]['parent_comentario_id'];
var obj = getLikesUnlikes(commentId);
if (parent == "0")
{
if(data[i]['like_unlike'] >= 1)
{
like_icon = "<img src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img style='display:none;' src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
else
{
like_icon = "<img style='display:none;' src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
comments = "\
<div class='comment-row'>\
<div class='comment-info'>\
<span class='commet-row-label'>De</span>\
<span class='posted-by'>" + data[i]['comment_sender_name'] + "</span>\
<span class='commet-row-label'>a las </span> \
<span class='posted-at'>" + data[i]['date'] + "</span>\
</div>\
<div class='comment-text'>" + data[i]['comment'] + "</div>\
<div>\
<a class='btn-reply' onClick='postReply(" + commentId + ")'>Responder</a>\
</div>\
<div class='post-action'>\ " + like_icon + " \
<span id='likes_" + commentId + "'> " + totalLikes + " Me Gusta </span>\
</div>\
</div>";
var item = $("<li>").html(comments);
list.append(item);
var reply_list = $('<ul>');
item.append(reply_list);
listReplies(commentId, data, reply_list);
}
}
$("#output").html(list);
});
}
function listReplies(commentId, data, list) {
for (var i = 0; (i < data.length); i++)
{
var obj = getLikesUnlikes(data[i].comentario_id);
if (commentId == data[i].parent_comentario_id)
{
if(data[i]['like_unlike'] >= 1)
{
like_icon = "<img src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img style='display:none;' src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
else
{
like_icon = "<img style='display:none;' src='img/NoMeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
var comments = "\
<div class='comment-row'>\
<div class='comment-info'>\
<span class='commet-row-label'>De </span>\
<span class='posted-by'>" + data[i]['comment_sender_name'] + "</span>\
<span class='commet-row-label'>a las </span> \
<span class='posted-at'>" + data[i]['date'] + "</span>\
</div>\
<div class='comment-text'>" + data[i]['comment'] + "</div>\
<div>\
<a class='btn-reply' onClick='postReply(" + data[i]['comentario_id'] + ")'>Responder</a>\
</div>\
<div class='post-action'> " + like_icon + " \
<span id='likes_" + data[i]['comentario_id'] + "'> " + totalLikes + " Me Gusta </span>\
</div>\
</div>";
var item = $("<li>").html(comments);
var reply_list = $('<ul>');
list.append(item);
item.append(reply_list);
listReplies(data[i].comentario_id, data, reply_list);
}
}
}
function getLikesUnlikes(commentId)
{
$.ajax({
type: 'POST',
async: false,
url: 'Envio_MeGusta.php',
data: {comentario_id: commentId},
success: function (data)
{
totalLikes = data;
}
});
}
function likeOrDislike(comentario_id,like_unlike)
{
$.ajax({
url: 'MeGusta_NoMeGusta.php',
async: false,
type: 'post',
data: {comentario_id:comentario_id,like_unlike:like_unlike},
dataType: 'json',
success: function (data) {
$("#likes_"+comentario_id).text(data + " likes");
if (like_unlike == 1) {
$("#like_" + comentario_id).css("display", "none");
$("#unlike_" + comentario_id).show();
}
if (like_unlike == -1) {
$("#unlike_" + comentario_id).css("display", "none");
$("#like_" + comentario_id).show();
}
},
error: function (data) {
alert("error : " + JSON.stringify(data));
}
});
}
</script>
Agregarcomentario.php
Enviomegusta.php
Listadocomentarios.php
megusta-nomegusta.php
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<link href="css/estilos.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-3.2.1.min.js" type="text/javascript"></script>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel-body">
<!--Inicio elementos contenedor-->
<div class="comment-form-container">
<form id="frm-comment">
<div class="input-row">
<input type="hidden" name="comentario_id" id="commentId"
placeholder="Name" /> <input class="input-field"
type="text" name="name" id="name" placeholder="Nombres" />
</div>
<div class="input-row">
<textarea class="input-field" type="text" name="comment"
id="comment" placeholder="Agregar comentario"> </textarea>
</div>
<div>
<input type="button" class="btn-submit" id="submitButton"
value="Publicar Ahora" /><div id="comment-message">Comentario ha sido agregado exitosamente!</div>
</div>
<div style="clear:both"></div>
</form>
</div>
<div id="output"></div>
<script>
var totalLikes = 0;
var totalUnlikes = 0;
function postReply(commentId) {
$('#commentId').val(commentId);
$("#name").focus();
}
$("#submitButton").click(function () {
$("#comment-message").css('display', 'none');
var str = $("#frm-comment").serialize();
$.ajax({
url: "AgregarComentario.php",
data: str,
type: 'post',
success: function (response)
{
var result = eval('(' + response + ')');
if (response)
{
$("#comment-message").css('display', 'inline-block');
$("#name").val("");
$("#comment").val("");
$("#commentId").val("");
listComment();
} else
{
alert("Failed to add comments !");
return false;
}
}
});
});
$(document).ready(function () {
listComment();
});
function listComment() {
$.post("ListaDeComentarios.php",
function (data) {
var data = JSON.parse(data);
var comments = "";
var replies = "";
var item = "";
var parent = -1;
var results = new Array();
var list = $("<ul class='outer-comment'>");
var item = $("<li>").html(comments);
for (var i = 0; (i < data.length); i++)
{
var commentId = data[i]['comentario_id'];
parent = data[i]['parent_comentario_id'];
var obj = getLikesUnlikes(commentId);
if (parent == "0")
{
if(data[i]['like_unlike'] >= 1)
{
like_icon = "<img src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img style='display:none;' src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
else
{
like_icon = "<img style='display:none;' src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
comments = "\
<div class='comment-row'>\
<div class='comment-info'>\
<span class='commet-row-label'>De</span>\
<span class='posted-by'>" + data[i]['comment_sender_name'] + "</span>\
<span class='commet-row-label'>a las </span> \
<span class='posted-at'>" + data[i]['date'] + "</span>\
</div>\
<div class='comment-text'>" + data[i]['comment'] + "</div>\
<div>\
<a class='btn-reply' onClick='postReply(" + commentId + ")'>Responder</a>\
</div>\
<div class='post-action'>\ " + like_icon + " \
<span id='likes_" + commentId + "'> " + totalLikes + " Me Gusta </span>\
</div>\
</div>";
var item = $("<li>").html(comments);
list.append(item);
var reply_list = $('<ul>');
item.append(reply_list);
listReplies(commentId, data, reply_list);
}
}
$("#output").html(list);
});
}
function listReplies(commentId, data, list) {
for (var i = 0; (i < data.length); i++)
{
var obj = getLikesUnlikes(data[i].comentario_id);
if (commentId == data[i].parent_comentario_id)
{
if(data[i]['like_unlike'] >= 1)
{
like_icon = "<img src='img/MeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img style='display:none;' src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
else
{
like_icon = "<img style='display:none;' src='img/NoMeGusta.png' id='unlike_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",-1)' />";
like_icon += "<img src='img/NoMeGusta.png' id='like_" + data[i]['comentario_id'] + "' class='like-unlike' onClick='likeOrDislike(" + data[i]['comentario_id'] + ",1)' />";
}
var comments = "\
<div class='comment-row'>\
<div class='comment-info'>\
<span class='commet-row-label'>De </span>\
<span class='posted-by'>" + data[i]['comment_sender_name'] + "</span>\
<span class='commet-row-label'>a las </span> \
<span class='posted-at'>" + data[i]['date'] + "</span>\
</div>\
<div class='comment-text'>" + data[i]['comment'] + "</div>\
<div>\
<a class='btn-reply' onClick='postReply(" + data[i]['comentario_id'] + ")'>Responder</a>\
</div>\
<div class='post-action'> " + like_icon + " \
<span id='likes_" + data[i]['comentario_id'] + "'> " + totalLikes + " Me Gusta </span>\
</div>\
</div>";
var item = $("<li>").html(comments);
var reply_list = $('<ul>');
list.append(item);
item.append(reply_list);
listReplies(data[i].comentario_id, data, reply_list);
}
}
}
function getLikesUnlikes(commentId)
{
$.ajax({
type: 'POST',
async: false,
url: 'Envio_MeGusta.php',
data: {comentario_id: commentId},
success: function (data)
{
totalLikes = data;
}
});
}
function likeOrDislike(comentario_id,like_unlike)
{
$.ajax({
url: 'MeGusta_NoMeGusta.php',
async: false,
type: 'post',
data: {comentario_id:comentario_id,like_unlike:like_unlike},
dataType: 'json',
success: function (data) {
$("#likes_"+comentario_id).text(data + " likes");
if (like_unlike == 1) {
$("#like_" + comentario_id).css("display", "none");
$("#unlike_" + comentario_id).show();
}
if (like_unlike == -1) {
$("#unlike_" + comentario_id).css("display", "none");
$("#like_" + comentario_id).show();
}
},
error: function (data) {
alert("error : " + JSON.stringify(data));
}
});
}
</script>
Agregarcomentario.php
Enviomegusta.php
Listadocomentarios.php
megusta-nomegusta.php