我将 Wicket.Ajax.ajax 与 AbstractDefaultAjaxBehavior 配对使用,将一些 javascript 计算数据发送到 java。但是在事件从 javascript 触发并到达 Java 之后,浏览器已被重定向到回调 url。
...web/product/1?7&6-1.IBehaviorListener.0-idsPanelPlace%3Floggged_id=332797
logggedidAjax = new AbstractDefaultAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
StringValue loggged_vkid = getRequest().getQueryParameters().getParameterValue("loggged_id");
String loggedId = (loggged_id != null) ? loggged_id.toString() : "null";
logger.info("ajax has comming with logged ID " + loggedId);
}
@Override
public void renderHead(final Component component, IHeaderResponse response) {
super.renderHead(component, response);
String componentMarkupId = getMarkupId();
Map<String, Object> map = new HashMap<>();
map.put("callbackUrl", logggedidAjax.getCallbackUrl());
PackageTextTemplate ptt = new PackageTextTemplate(VKIDsPanel.class, "id_callback.js");
OnDomReadyHeaderItem onDomReadyHeaderItem = OnDomReadyHeaderItem.forScript(ptt.asString(map));
response.render(onDomReadyHeaderItem);
}
};
add(logggedidAjax);
至于js代码-
var wcall = Wicket.Ajax.ajax({ u: '${callbackUrl}' + '?loggged_id='+ response.session.mid });
为什么浏览器重定向到 url,因为它是 Ajax?如何防止重定向?