[英]After ajax call redirect the response to another jsp
我有一个来自jsp页面的ajax调用,该页面将请求发送到控制器中的ModelandView类。
test.jsp中的Ajax调用
function currentposition(l1, l2) {
var url="home/test";
var data= 'lat1=' + l1 + '&lat2=' + l2;
$.ajax({
type:"POST",
url:url,
data:data,
dataType:"json",
success:function(responseJSON){
alert(responseJSON);
}
});
}
调节器
public ModelandView gettest(@Context HttpServletRequest request) {
ModelandView responseView = new ModelandView(new JsonView());
//some code here
if (somecondition) {
response.addObject("JSONdata", vehicleID);
}
else {
System.out.println("Not present");
}
return responseView;
}
我从控制器收到对test.jsp的响应,并且得到了预期的结果。 但我想将结果重定向到another.jsp,结果应显示在下拉列表中,如下所示。
another.jsp
<select class="test" id="vehicle-id">
<option>...</option>
</select>
我该怎么做呢?
尝试以下这些添加您的AJAX调用的成功响应:
var surl = '<%=request.getContextPath()%>/registration';
window.location.replace(surl);
您可以尝试通过以下方式提交表单:
...
success:function(responseJSON){
var form = $('<form></form>').attr('action','another.jsp');
$(form).attr('method','POST');
var ele = $('<input type="text">').attr('name','txtjson');
$(ele).val(responseJSON);
$(ele).appendTo($(form));
$(form).appendTo('body');
$(form).submit();
}
...
然后在您的another.jsp文件中,仅接收POST变量txtjson
。
编写另一个返回another.jsp
控制器
从您的test.jsp
,给window.location = /home/test?lat1=' + l1 + '&lat2=' + l2;
处理json数据后,请重定向到另一个控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.