【JS】改变window.location,使得Ajax调后台,返回状态OK即翻页的小技巧
【核心语句】
window.location="address"
我的address是在控制器里配的,具体如下:
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class PageCtrl { ... @RequestMapping("dmm/gotoAddPrj") public String gotoAddPrj() { return "dmm/addPrj"; } ... }
【示例代码】
$.ajax({ url:"../saveProject", data:{fromDsIdx:fromDsIdx,toDsIdx:toDsIdx,tables:tables,projectName:projectName,uid:uid}, type:"post", dataType:"json", timeout:5000, error:function(xhr,textStatus,errorThrown){alert('ajax error')}, success:function(rsps){ if(rsps.status==true){ window.location="../dmm/gotoListPrj"; }else{ alert(rsps.errMsg); } }, });
END