0

如何在执行 ajax 调用后刷新页面。我的 Ajax 调用是

 $.ajax({
         type: "POST",
         data: data,
         url:"{{ path('v2_pm_patents_trashpatents') }}",
         cache: false
});

这个ajax执行的方法是

 public function trashpatentAction(Request $request){
    if ($request->isXmlHttpRequest()) {
        $patent_id = $request->get("pid");
        $em = $this->getDoctrine()->getEntityManager();
        $patent = $em->getRepository('MunichInnovationGroupPatentBundle:SvPatents')->find($patent_id);
        if (!$patent) {
            throw $this->createNotFoundException('No patent found for id '.$patent_id);
        }
        $patent->setIs_deleted(1);
        $em->flush();
    }
}

编辑

投资组合控制器指数行动

public function indexAction(Request $request) {
     $switch_form = $this->createForm(new SwitchPortfolioType($portfolios));
     ////rest of action code
     return $this->render('MunichInnovationGroupPatentBundle:Portfolio:index.html.twig', array('new_patentgroup_form' => $new_patentgroup_form->createView(),'switch_form' => $switch_form->createView(), 'new_form' => $new_form->createView(), "portfolios" => $portfolios ,"selected_portfolio" => $selected_portfolio,"portfolio_groups" => $portfolio_groups,"patents" => $patents));

}

索引.html.twig

 <form name="portfolios" action="{{ path('v2_pm_portfolio') }}" method="post" >
            {{ form_widget(switch_form) }}
            <input type="submit"class="portfolio_input button2 tooltip" value="Switch">
 </form> 

开关组合类型

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class SwitchPortfolioType extends AbstractType
{
public function __construct($portfolios)
{
    $this->portfolios = $portfolios;
}


public function buildForm(FormBuilder $builder, array $options)
{
    $builder
    ->add('', 'choice', array(
        'choices'   => array(
                'test' => 'Test'
        ),
            'empty_value' => 'Switch your Portfolio',
    ));
}

public function getName()
{
    return 'switch_portfolio';
}

}

在此操作结束时,我想刷新页面

我怎样才能做到这一点?

4

2 回答 2

2

刷新必须在 javascript 中完成。我不确定为什么你会通过 ajax 发布只是为了重新加载页面,为什么不只是正常发布呢?

无论如何,按照您的要求,我会在控制器中返回一些简单的 JSON 响应以表示成功,然后在 ajax 回调中执行以下操作:

$.ajax({
     type: "POST",
     data: data,
     url:"{{ path('v2_pm_patents_trashpatents') }}",
     cache: false,
     success: function(data) {
         // optionally check if the response is what you wanted
         //if (data.response == 'deleted') {
             document.location.reload(true);
         //}
     }
});
于 2012-06-24T19:52:29.273 回答
0

使用jQuery:

$('your_form').disable=true;

纯JS:

your_form.disabled = true;
于 2012-10-22T18:04:51.800 回答