我无法访问我的Bootstrap模式

时间:2016-03-31 03:19:58

标签: jquery ajax twitter-bootstrap-3 laravel-5.2

在制作模态save/update function后,我无法访问我的Bootstrap模态。这是我的代码。但是当我发表评论.done(function(msg))时,我可以再次访问它 希望你能帮助我们。

var postId= 0;
var postBodyElement= null;
$('.post').find('.interaction').find('.edit').on('click', function(event) {
        event.preventDefault();

        postBodyElement= event.target.parentNode.parentNode.childNodes[1];
        var postBody= postBodyElement.textContent;
        postId= event.target.parentNode.parentNode.dataset['postid'];
        $('#post-body').val(postBody);
        $('#edit-modal').modal();
});

//saving the update of your post..
$('#modalSave').on('click', function() {
        $.ajax({
                method: 'POST',
                url: url,
                data: {post: $('#post-body').val(), postId: postId, _token: token}
        })
        .done(function(msg)) {
                $(postBodyElement).text(msg['new_body']);
                $('#edit-modal').modal('hide');
        };
});

这是我的模式形式..

<div class="modal fade" tabindex="-1" role="dialog" id="edit-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Edit post</h4>
            </div>
            <!--Modal body-->
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="post-body">Edit your post</label>
                        <textarea class="form-control" name="post-body" id="post-body" rows="5"></textarea>
                    </div>
                </form>
            </div>
            <!--Modal footer-->
             <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" id="modalSave">Save changes</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

1 个答案:

答案 0 :(得分:0)

我在这里犯了一个错误,.done(function(msg))而不是.done(function(msg)

//exist of close parenthesis at .done(function(msg))
.done(function(msg)) {
        $(postBodyElement).text(msg['new_body']);
        $('#edit-modal').modal('hide');
});

而不是这个。

.done(function(msg) {
        $(postBodyElement).text(msg['new_body']);
        $('#edit-modal').modal('hide');
});