我想将 id 存储在全局变量中,然后存储此 id 以进行表单编辑这是我的 xml 请求:
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;
}
这是我的ajax代码:
$("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 }) }}";
});
这是包含 id 的 myjson 响应:
{"success":true,"title":"invoice","id":57,"notes":"gjgjgjgjg","accountid":1,"clientid":"5","status":"sent","totalamount":"90000","paidamount":"45000","balanceamount":"45000","createdby":1,"updatedby":1,"createddatetime":{"date":"2013-10-03 17:37:00","timezone_type":3,"timezone":"Asia\/Karachi"},"updateddatetime":{"date":"2013-10-03 17:37:00","timezone_type":3,"timezone":"Asia\/Karachi"}}
当我提醒 invoiceid 时,它会显示 result.id 的值,但 invoiceid 没有传递给点击功能,我该怎么做?