Search code examples
javascriptajaxrichtextarea

Display data in Rich Textarea on (ajax success) in javascript?


Here My Code:


<textarea 
 class="textarea" id="about_us" placeholder="Place some text here"
 style="width: 100%; height: 100%; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"
>
</textarea >

And My JavaSript code is I Recieve Data But Only Rich Textarea us not showing See This RichTextarea Image

<script>

$(document).ready(function () {
$(document).on('click', '.editbtn', function(){  
          var Pedit_id = $(this).attr("id");  
          $.ajax({  
               url:"../fetch/editproduct.php",  
               method:"POST",  
               data:{Pedit_id:Pedit_id},  
               dataType:"json",  
               success:function(data){ 
                    $('#about_us').val(data.product_dec);

               }  
          });  
     });
});
</script>

Please tell me where I mistake because I want to get data from MySQL database using ajax on button click and show to specific textarea please solve this . Regards Ahsan Javed


Solution

  • You are trying to set the value data.product_dec in element with id about_us. Since you are using Jquery I would suggest using .val() method of JQuery to achieve the desired outcome.

    Refer:

    Update:

    $(document).ready(function () {
    $(document).on('click', '.editbtn', function(){  
              var Pedit_id = $(this).attr("id");  
              $.ajax({  
                   url:"/fetch/editproduct",  
                   method:"POST",  
                   data:{Pedit_id:Pedit_id},  
                   dataType:"json",  
                   success:function(data){ 
                        $('#about_us').val(data.product_dec);
    
                   }  
              });  
         });
    });