Я новый программист в Laravel 5.2.4.Я столкнулся с проблемой, когда пытался отредактировать кнопку в приложении социальной сети, которое пытался создать.Кнопка редактирования не всплывала.Возможно, я что-то делаю не так.Любезно помочь.это мой код.
**** Мой файл app.js ****
var postId = 0;
$('.post').find('.interaction').find('edit').on(2).on('click', function(event) {
event.preventDefault();
var postBody = event.target.parentNode.parentNode.childNodes[1].textContent;
postId = event.target.parentNode.parentNode.dataset['postid'];
$('#post-body').val(postBody);
$('#edit-modal').modal();
});
$('modal-save').on('click', function() {
$.ajax({
method: 'POST',
url:url,
data: {body: $('#post-body').val(), postId: postId, _token: token}
})
.done(function (msg){
console.log(msg['message']);
});
});
**** Мой контроллер dashboard.php ****
@extends('layouts.master')
@section('content')
@include('includes.message-block')
<section class="row new-post">
<div class="col-md-6 col-md-offset-3">
<header><h3>What do you have to say?</h3></header>
<form action="{{url('createpost')}}" method="post">
<div class="form-group">
<textarea class="form-control" name="body" id="body" rows="5" placeholder="Your Post"></textarea>
</div>
<button type="submit" class="btn btn-primary">Create Post</button>
<input type="hidden" name="_token" value="{{Session::token()}}" name="_token">
</form>
</div>
</section>
<section class="row posts">
<div class="col-md-6 col-md-offset-3">
<header><h3>What other people say...</h3></header>
@foreach($posts as $post)
<article class="post" data-postid="{{$post->id}}">
<p>{{$post->body}}</p>
<div class="info">
Posted by {{$post->user->first_name}} on {{$post->created_at }}
</div>
<div class="interaction">
<a href="#">Like</a> |
<a href="#">Dislike</a> |
@if(Auth::user() == $post->user)
<a href="#">Edit</a> |
<a href="{{route('post.delete', ['post_id'=>$post->id])}}">Delete</a> |
@endif
</div>
</article>
@endforeach
</div>
</section>
<div class="modal" 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">
<h4 class="modal-title">Edit Post</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="post-body">Edit the Post</label>
<textarea class="form-control" name="post-body" id ="post-body" row ="5"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
var token = '{{Session::token()}}';
var url = '{{route('edit')}}';
</script>
@endsection