项目中 前台接口 请求项目移植的问题

一、在项目的public目录下,配置前台的接口请求文件

在项目中示例

1、在前台js目录中配置这个js路径

var config = {
// apiUrl: 'http://' + window.location.host + '/BingooDirectedSales/public/sales',
apiUrl : 'http://' + window.location.host + '/sales',
// testUrl : 'http://' + window.location.host + '/BingooDirectedSales/public',
version: '1.0',
company: 'bingoo',
}

2、在请求接口中,使用配置文件接口进行请求

$scope.details = function () {
dialogLoading();
var data = {};
$scope.productionid = data.id = $location.search().productid;
$http.post( config.apiUrl + '/jigouDetail/index',
data,
{headers: {'Authorization': 'Bearer ' + store.get('token')}}
).success(function(msg){
removeLoading();
if(msg.code === 1000) {
$scope.data = msg.data;
$rootScope.globalproduction = msg.data;
var now = msg.data.now * 1000;
var deadline = msg.data.trust_last_time[msg.data.trust_last_time.length-1] * 1000;
//alert($scope.data.now + '------' + $scope.data.trust_last_time);
if($scope.data.now > $scope.data.trust_last_time[$scope.data.trust_last_time.length-1]){
$scope.haha = false;
}else{
$scope.haha = true;
}
$('#timer').attr('id',msg.data.trust_id);
setInterval("show_time(" + deadline + ",'" + msg.data.trust_id + "')",1000);

}
}).error(function(error) {
alert(error.message);
});
}

其中:

对于这样一个URL

扫描二维码关注公众号,回复: 6233831 查看本文章

http://www.php230.com :80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere

我们可以用javascript获得其中的各个部分
1, window.location.href
整个URl字符串(在浏览器中就是完整的地址栏)
本例返回值:
代码如下 复制代码
http://www.php230.com :80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere

2,window.location.protocol
URL 的协议部分
本例返回值:http:

3,window.location.host
URL 的主机部分
本例返回值:www.php230.com

4,window.location.port
URL 的端口部分
如果采用默认的80端口(update:即使添加了:80),那么返回值并不是默认的80而是空字符
本例返回值:""

5,window.location.pathname
URL 的路径部分(就是文件地址)
本例返回值:/fisker/post/0703/window.location.html

6,window.location.search
查询(参数)部分
除了给动态语言赋值以外,我们同样可以给静态页面,并使用javascript来获得相信应的参数值
本例返回值:?ver=1.0&id=6

7,window.location.hash
锚点
本例返回值:#imhere

猜你喜欢

转载自www.cnblogs.com/lvfish/p/10861263.html