Jump to content
php.lv forumi
  • 0

Tikko pievienotā komenta parādīšana augšgalā, laika nomaiņa


Cibiņš

Question

Kā lai nosorto ka tikko pievienotais komentārs pievienojas komentāru listes augšgalā nevis apakšā? Kā lai norefrešo laiku tiklīdz iepriekšējais komentārs pievienots??

 

$(function() {

               $("#add").click(function() {


                   var ajaxOpts = {
  	                 type: "post",
  	                 url: "resources/lib/add-comment.php",
  	                 data: "&author=" + $("#leaveComment").find("input#userid").val() + "&comment=" + $("#leaveComment").find("textarea#comment").val()+"&pagehash=" + $("#leaveComment").find("input#pagehash").val() + "&time=" + $("#leaveComment").find("input#time").val(),
  	                 success: function(data) {

  		                 var div = $("<div>").addClass("row").appendTo("#comments");

  		                 $("<div>").text($("#leaveComment").find("input#userid").val()).appendTo(div);
  		                 $("<div>").addClass("time").text($("#leaveComment").find("input#time").val()).appendTo(div);
  		                 $("<div>").addClass("comment").text($("#leaveComment").find("textarea#comment").val()).appendTo(div);

  		                 $("#leaveComment").find("textarea#comment").val("");
  		                 $("#leaveComment").find("input#time").val("<? echo time(); ?>");   		                 
  	                 }
                   };
                   $.ajax(ajaxOpts);
               });


               $.getJSON("resources/lib/comments.php?jsoncallback=?", function(data) {


                   for (var x = 0; x < data.length; x++) {


  	                 var div = $("<div>").addClass("row").appendTo("#comments");


  	                 $("<div>").addClass("name").text(data[x].name).appendTo(div);
  	                 $("<div>").addClass("addate").text(data[x].addate).appendTo(div);
  	                 $("<div>").addClass("comment").text(data[x].comment).appendTo(div);
                   }
               });        
           });  

Edited by Cibiņš
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Nezin neviens kā refrešot šādu (laiks jeb time()) pēc inserta pamatojoties uz augstākesošo kodu

 

$("#leaveComment").find("input#time").val("<? echo time(); ?>");

 

??????????????????????????

Edited by Cibiņš
Link to comment
Share on other sites

  • 0

Paldies, atrisināju!

 

add-comment.php vaidzēj

echo time();

un iekš javaskripta vaidzēj nomainīt

$("#leaveComment").find("input#time").val("<? echo time(); ?>");

uz

$("#leaveComment").find("input#time").val(data);

Edited by Cibiņš
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...