i have a problem when i click to post button i want data appeared in my page without refreshing page and add to that i want to store those data on my db and the next time i visit this page i find those data
<form method="post">
<textarea id="txt" class="form-control input-lg no-border" rows="2"
placeholder="What are you doing?..."></textarea>
<script>
$(document).ready(function() {
$("#btnpost").click(function () {
var text = $('#txt').val();
$.ajax({
type: 'POST',
url: '{{ path('group_addpub') }}',
data: {desc: text}
});
$("#publication").prepend('<div class="panel panel-success rounded shadow" style="text-align: left;margin-bottom: 5px;">' +
'<div class="panel-heading no-border">'+
'<div class="pull-left half">'+
'<div class="media" style="text-align: left;">'+
'<div class="media-object pull-left" style="margin-top: 35px;">'+
'<img src="http://bootdey.com/img/Content/avatar/avatar2.png" style="width: 40px;height: 40px;">' +
'</div>'+
'</div>'+
'</div>'+
'<a href="">test profile</a>'+
'<span class="text-white h6" style="display: block; color: black;">on 8th June, 2014</span>'+
'<br>'+
'<span style="color: black;margin-bottom: 10px;word-break: break-all ">'+text+ '</span>'+
'</div>'+
'</div>'+
'<div class="panel-footer">'+
'<form action="#" class="form-horizontal">'+
'<div class="form-group has-feedback no-margin">'+
'<div style="text-align: right;margin-top: 32px;">'+
'<a href=""><img src="{{ asset('Groupe/img/like-icon.png') }}" style="width:5%;"></a>'+
'<a href="" ><img src="{{ asset('Groupe/img/Unlike-icon.png') }}" style="width:5%;"></a>'+
'</div>'+
'<input class="form-control" type="text" placeholder="Votre commentaire ici..." style="width: 95%;margin-left: 10px;">'+
'</div>'+
'</form>'+
'</div>');
$('#txt').val('');
});
});
</script>
</form>
this is my controller action
public function addpubicationAction(Request $request)
{
if ($request->isXmlHttpRequest() && $request->isMethod('post') ) {
$em = $this->getDoctrine()->getManager();
$des = $request->get('txt');
$publication = new Publication();
$publication->setDescription($des);
$em->persist($publication);
$em->flush();
}
}
this is my routing file
group_group_photos:
path: /photos
defaults: { _controller: GroupGroupBundle:Group:photosGroupe}
group_new:
path: /{id}
defaults: { _controller: GroupGroupBundle:Group:newGroupe}
group_addpub:
path: /addpub
defaults: { _controller: GroupGroupBundle:Group:addpubication}