//说明:在页面中进行请求的时候进行拼接,底下的方法是用来获取ip地址加端口号加项目名(在进行ajax请求的时候,url是底下的值加后端给的接口)
function basePath()
{
//获取当前网址,如: http://localhost:80/jflow-web/index.jsp
var curPath=window.document.location.href;
console.log(curPath);
//获取主机地址之后的目录,如: jflow-web/index.jsp
var pathName=window.document.location.pathname;
console.log(pathName)
var pos=curPath.indexOf(pathName);
//获取主机地址,如: http://localhost:80
var localhostPaht=curPath.substring(0,pos);
//获取带"/"的项目名,如:/jflow-web
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
console.log(localhostPaht+projectName)
return localhostPaht+projectName;
}
直接获取页面url的前缀,请求时用
最新推荐文章于 2024-05-24 10:24:44 发布