将PHP / SQL变量添加到Bootbox文本区域

I'm playing around with a PHP heavy social network for my friends. I am trying to add an edit post function via a Bootbox. Here's the code for the EDIT button: <button class='edit_button' id='edit$id'>Edit</button> And the function it calls:

    $(document).ready(function() {                  
      $('#edit<?php echo $id; ?>').on('click', function() {
       bootbox.prompt({
         title: "Edit your post!",
         inputType: 'textarea',
         backdrop: 'true',
         onEscape: 'true',
         callback: function (result) {
           console.log(result);
          }
        });
      });
    });

I tried putting value: '<?php echo $body; ?>', into the bootbox code, but that breaks the rest of my javascript code.

The $id in the button calls the specific post $id and that would reference the $body of the post.

How do I have the text of the $body automatically inserted into the textarea?

I was looking in the docs of bootbox.js and I found this init function.

Based on your code, you can do something like this:

$('#edit<?php echo $id; ?>').on('click', function() {
        var prompt = bootbox.prompt({
            title: "Edit your post!",
            inputType: 'textarea',
            backdrop: 'true',
            onEscape: 'true',
            callback: function (result) {
                console.log(result);
            }
        });

        prompt.init(function() {
            $.ajax({
                url: '/path/to/file',
                type: 'default GET (Other values: POST)',
                dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
                data: {postID: '<?php echo $id; ?>'},
                beforeSend: function() {
                    console.log('pre loader');
                }
            })
            .done(function(data) {
                prompt.find('.bootbox-input-textarea').val('done');
            })
            .fail(function() {
                prompt.find('.bootbox-input-textarea').val('error');
            })
            .always(function(data) {
                console.log("complete");
            });
        });
    });

Use the init function, to perform an ajax call and load the post content inside the textarea create by bootbox.js, once it's loaded you can get the value edited by the bootbox.js callback function.