我试图从productlisting.html页面重定向到search.html上的按钮,但URL在URL栏附加的点击采用了棱角分明是:重定向到一个HTML页面采用了棱角分明
/仪表板,HTML /产品清单1 html的#/#%2Fsearch.html%3Fquery =饼干
,我希望它是这样
/dashboard-html/search.html%?query=biscuits
我的代码script.js是:
Array.prototype.chunk = function (groupsize) {
var sets = [];
var chunks = this.length/groupsize;
for (var i = 0, j = 0; i < chunks; i++, j += groupsize) {
sets[i] = this.slice(j, j + groupsize);
}
return sets;
};
var data_bind=angular.module('my_app', []);
data_bind.controller('productController', function ($scope, $http, $location)
{
var isProductListingpage = false;
$scope.init = function (isProductListpage){
isProductListingpage = isProductListpage;
// if this is not search page, get the query params from url and get the products to show from server
if(!isProductListingpage)
{
var queryParam = location.search;
var request_url='http://dmsp1-kakash.boxfuse.io:9000/products?'+queryParam;
sendRequest(request_url);
}
}
function sendRequest(request_url)
{
$http({
method : 'GET',
url : request_url,
headers : {'Content-Type' : 'application/json'}
}).success(function(response){
if(response.errors){
$scope.errorName = response.errors.name ;
$scope.errorUserName = response.errors.username;
$scope.errorEmail = response.errors.email;
}
else
{
$scope.product = response.data.products;
$scope.productGroups = $scope.product.chunk(3);
}
});
}
$scope.search_field={};
$scope.searchdata= function()
{
var queryParam = "query="+encodeURI($scope.search_field.search);
var request_url='http://dmsp1-kakash.boxfuse.io:9000/products?'+queryParam;
// If this is product listing page, we need to redirect to search page,
// otherwise make a request to server
if(isProductListingpage) {
//$window.location.href = '/index.html'
$location.url('#/search.html?'+queryParam);
}
else {
sendRequest(request_url);
}
}
$scope.search_field1={};
$scope.search_page= function(event)
{
var $target = $(event.target);
if($target.hasClass('sub-category'))
{
var subCategory = $target.clone() //clone the element
.children() //select all the children
.remove() //remove all the children
.end() //again go back to selected element
.text();
var $temp = $target.closest('.submenu');
var $mainCategoryElement = $temp.siblings('.main-category').first();
var mainCategory = $mainCategoryElement.text();
// Encode both the values
subCategory = encodeURI(subCategory);
mainCategory = encodeURI(mainCategory);
var queryParam = 'cat='+mainCategory+"&subcat="+subCategory;
var request_url='http://dmsp1-kakash.boxfuse.io:9000/products?'+queryParam;
// If this is product listing page, we need to redirect to search page,
// otherwise make a request to server
if(isProductListingpage) {
$location.url('#/search.html?'+queryParam);
}
else {
sendRequest(request_url);
}
}
}
});``
2016-05-19
kriti