Javascript 动态添加URL中变量旁边的路径。如何在变量之前移动它?
只是一些介绍: 在电子商务模板中,基于Symfony的我使用AJAX请求从可用页面无限滚动加载所有产品。当我有如下清晰的URL时,一切工作都很完美:Javascript 动态添加URL中变量旁边的路径。如何在变量之前移动它?,javascript,jquery,ajax,Javascript,Jquery,Ajax,只是一些介绍: 在电子商务模板中,基于Symfony的我使用AJAX请求从可用页面无限滚动加载所有产品。当我有如下清晰的URL时,一切工作都很完美: http://example.com/path http://example.com/path/page1.ajax?mode=grid&max=60&min=0&sort=newest var u = new URL("http://example.com/path/?mode=grid&max=60&
http://example.com/path
http://example.com/path/page1.ajax?mode=grid&max=60&min=0&sort=newest
var u = new URL("http://example.com/path/?mode=grid&max=60&min=0&sort=newest")
var newUrl = u.origin + u.pathname + 'page.ajax' + u.search;
我正在使用ajax请求从可用页面加载产品,这里有一些代码需要检查注意,不是全部功能代码,而是影响URL的部分:
$().ready(function(){
infiniteCollectionInit('{{ (request.url~'page1.ajax') }}');
});
function infiniteCollectionLoad(url, mode){
infiniteCollectionPage++;
url = url.replace('page1.ajax', 'page' + infiniteCollectionPage + '.ajax');
}
这只是添加了page1.ajax、page2.ajax。。。在URL的末尾
问题始于页面中使用过滤器时,在这种情况下,URL转换为:
http://example.com/path/?mode=grid&max=60&min=0&sort=newest
现在,当向下滚动并需要加载下一页的项目时,URL为:
http://example.com/path/?mode=grid&max=60&min=0&sort=newestpage1.ajax
有人能帮我在变量之前添加page1.ajax吗
http://example.com/path
http://example.com/path/page1.ajax?mode=grid&max=60&min=0&sort=newest
var u = new URL("http://example.com/path/?mode=grid&max=60&min=0&sort=newest")
var newUrl = u.origin + u.pathname + 'page.ajax' + u.search;
谢谢。应该是这样的:
http://example.com/path
http://example.com/path/page1.ajax?mode=grid&max=60&min=0&sort=newest
var u = new URL("http://example.com/path/?mode=grid&max=60&min=0&sort=newest")
var newUrl = u.origin + u.pathname + 'page.ajax' + u.search;
如果从上一个URL重新使用URL,则可能需要将u.pathname替换为固定路径。否则,您将继续添加到它。这非常适合。正是我想要的。谢谢。