jfinal 拦截器中判断是否为pjax请求

in with 0 comments
public class PjaxInterceptor implements Interceptor{

	IndexService service=IndexService.me;
	
	@Override
	public void intercept(Invocation inv) {
 
		Controller c=inv.getController();
		
		boolean isPjax = "true".equalsIgnoreCase(c.getHeader("X-PJAX"));
		
		c.setAttr("isPjax", isPjax);
		inv.invoke();
	}

}

将该拦截器注册为全局拦截器即可在模板中判断请求是否为pjax请求,然后根据请求类型渲染不同的代码片段,配合jquery.pjax.js即可轻松实现pjax渲染页面

Responses /