jQuery是寻找一个 JSON 类型的搜索结果,但因为重定向自动处理,它将接收 生成的html源 你的
login.htm页面。
一种想法是通过将
redirect变量添加到结果对象并在JQuery中进行检查来让浏览器知道它应该重定向:
$(document).ready(function(){ jQuery.ajax({ type: "GET", url: "populateData.htm", dataType:"json", data:"userId=SampleUser", success:function(response){ if (response.redirect) { window.location.href = response.redirect; } else { // Process the expected results... } }, error: function(xhr, textStatus, errorThrown) { alert('Error! Status = ' + xhr.status); } }); });您还可以在响应中添加标头变量,然后让浏览器决定重定向的位置。在Java中,执行重定向而不是重定向,
response.setHeader("REQUIRES_AUTH","1")而在JQuery中执行成功(!)://.... success:function(response){ if (response.getResponseHeader('REQUIRES_AUTH') === '1'){ window.location.href = 'login.htm'; } else { // Process the expected results... } }//....希望能有所帮助。



