Thursday, 3 October 2013

how to get form id from ajax and set it in click function in symfony2

how to get form id from ajax and set it in click function in symfony2

i want to store id in global variable and then store this id for form edit
here is my xml request:
if($request->isXmlHttpRequest()) {
$response = new Response();
$output = array('success' => true, 'title' => $entity->gettitle(),
'id' => $entity->getId(), 'notes' => $entity->getnotes(),
'accountid' => $entity->getaccountid(), 'clientid' =>
$entity->getClientID(), 'status' => $entity->getstatus(),
'totalamount' => $entity->getTotalAmount(), 'paidamount' =>
$entity->getPaidAmount(), 'balanceamount' =>
$entity->getBalanceAmount(), 'createdby' =>
$entity->getcreatedby(), 'updatedby' => $entity->getupdatedby(),
'createddatetime' => $entity->getcreateddatetime(),
'updateddatetime' => $entity->getupdateddatetime());
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
return $response;
}
and here is my ajax code:
$("form").submit(function(e) {
e.preventDefault();
var url = $(this).attr('action');
var data = $(this).serialize();
$.ajax({
type: "POST",
url: url,
data: data,
}).done(function( result ) {
invoiceid=result.id;
if(result.success) {
$('#result').css({'color':'black','background-color':'#8F8','display':'Block','width':'200px'});
$('#result').html('Invoices Record Inserted');
setTimeout(function(){
$('#result').hide();
},3000);
}
});
this.reset();
});
$("#edit").click(function(){
window.location.href= "{{ path('invoices_edit', {'id': invoiceid }) }}";
});
when i alert invoiceid then it show value of result.id but invoiceid not
pass to click function,how i do this?

No comments:

Post a Comment