javascript - Displaying existing content in editable textarea -


hi trying make editable page javascript , php , want display whats stored in area not work. meant blog page meaning there multiple posts. , unsure whether problem within js or php.

this javascript using. console.log() writes post_id unassigned.

$(document).on('click', '.editbutton', function () {           var post_id = $(this).parent().data('id');          var self = this;           $.getjson(settings.server, {post_id: post_id},  function(data){                 var editabletext = '<textarea class="editpostbody">' + data.body + '</textarea>';                 console.log(post_id);                  $(".post").parent().replacewith(editabletext);          });     });  var formatpost = function(d) {          var s = '';    s = '<div class="post" data-id="' + d.post_id + '"><h2 class="postheading">' + d.title +'</h2>';    s += d.body;   s += '<p> posted on: ' + d.date + '</p>';    s += '<div class="btn editbutton">edit post</div>'   s += '</div>'          return s;     }; 

and php file connection db established prior

if(count($_get)) {  if(isset($_get['post_id'])){  get_post_id( $_get['post_id']);  }  } else{  get_posts(); }   function get_posts() {  global $link;  // $sql = "select count(1) posts";  // $result = mysqli_query($link, $sql); // $total = mysqli_fetch_array($result);  $sql = "select * post order date desc limit 0, 5";  $result = mysqli_query($link, $sql); $rows = array();  while ($row = mysqli_fetch_assoc($result)) {     $rows[] = $row; }     // $json = '{"total":"' . $total[0] . '","posts":'; $json = json_encode($rows); // $json .= "}";  print($json);    }   function get_post_id($postid){   global $link;   $sql = "select * post id = $postid";     $result = mysqli_query($link, $sql);  $tosend = mysqli_fetch_assoc($result);     print json_encode($tosend); } 

thank you

i modified code this

function get_post_id($postid){    global $link;    $sql = "select * post post_id = $postid";     $result = mysqli_query($link, $sql);   $tosend = mysqli_fetch_assoc($result);     print json_encode($tosend); } 

and js

$(document).on('click', '.editbutton', function () {            var post_id = $(this).parent().data('id');         // console.log(post_id);           var self = this;           $.getjson(settings.server, {post_id: post_id},  function(data){                 var editabletext = $('<textarea class="editpostbody">' + data.body + '</textarea>');             console.log(post_id);                 $(".post").parent().replacewith(editabletext);          }); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -