jquery - How to get id from ajax request and then send it to symfony function? -


i make create function want store id in variable , pass id edit function,i write code error exist,how this? here code:

  var invoiceid;   $("form").submit(function(e) {                          e.preventdefault();          var url = $(this).attr('action');          var data = $(this).serialize();          $.ajax({             type: "post",             url: url,             data: data,          })          .success(function( result )  {                 invoiceid=result.id;                 $("#edit").click();              if(result.success) {                 $('#result').css({'color':'black','background-color':'#8f8','display':'block','width':'200px'});                 $('#result').html('invoices record inserted');                 settimeout(function(){                     $('#result').hide();                     },3000);                     window.location.href = "{{ path('invoicepreview') }}";             }          });          this.reset();      });      $("#edit").click(function(){   = "{{ path('invoices_edit', {'id': invoiceid }) }}"; }); 

here create function:

 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));      } 

here edit function:

public function editaction($id) {     $em = $this->getdoctrine()->getmanager();      $entity = $em->getrepository('invoicesinvoicesbundle:invoices')->find($id);      if (!$entity) {         throw $this->createnotfoundexception('unable find invoices entity.');     }      $editform = $this->createform(new invoicestype(), $entity);     $deleteform = $this->createdeleteform($id);      return $this->render('invoicesinvoicesbundle:invoices:edit.html.twig', array(         'entity'      => $entity,         'edit_form'   => $editform->createview(),         'delete_form' => $deleteform->createview(),     )); } 

here error:

variable "invoiceid" not exist in invoicesinvoicesbundle:invoices:new.html.twig @ line 362  

if you're going generating paths dynamically within js, if you're doing loads of ajax-y stuff, want add fos's js routing bundle project

after correct configuration js path like

routing.generate('invoices_edit', { id: invoiceid }); 

instructions on how configure paths , routes use jsbundle can found here


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -