其他分享
首页 > 其他分享> > 【JS】改变window.location,使得Ajax调后台,返回状态OK即翻页的小技巧

【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

标签:OK,uid,翻页,Controller,rsps,window,dmm,Ajax,location
来源: https://www.cnblogs.com/pyhy/p/16057590.html