简体   繁体   English

URL中动态添加的路径,位于变量旁边。 如何在变量前移动它?

[英]Dynamically added path in URL going next to the variables. How can I move it before variables?

Just some intro: 只是一些介绍:

In ecommerce template, "Symfony" based I'm loading all the products from available pages (Infinite scroll) using AJAX request. 在电子商务模板中,基于“ Symfony”,我正在使用AJAX请求从可用页面(无限滚动)加载所有产品。 Everything working perfect when I have clear URL like this: 当我拥有清晰的URL时,一切工作正常:

http://example.com/path

I'm loading products from available pages with ajax request, here some code to check (Note, not the whole functional code, but the part which affects URL): 我正在使用ajax请求从可用页面加载产品,这里有一些代码需要检查(注意,不是整个功能代码,而是影响URL的部分):

$().ready(function(){
   infiniteCollectionInit('{{ (request.url~'page1.ajax') }}');    
});

function infiniteCollectionLoad(url, mode){
   infiniteCollectionPage++;
   url = url.replace('page1.ajax', 'page' + infiniteCollectionPage + '.ajax');
}

This simply adding page1.ajax, page2.ajax ... at the end of the URL 只需在网址末尾添加page1.ajax, page2.ajax ...

The problem starting at the point when filters are used in page, In that case the URL transforms to this: 问题始于在页面中使用过滤器时,在这种情况下,URL转换为:

http://example.com/path/?mode=grid&max=60&min=0&sort=newest

Now when scrolling down and it need to load next page's items the URL is: 现在,当向下滚动并需要加载下一页的项目时,URL为:

http://example.com/path/?mode=grid&max=60&min=0&sort=newestpage1.ajax

Can anyone help me out to add the page1.ajax before variables like this: 任何人都可以帮我在像这样的变量之前添加page1.ajax

http://example.com/path/page1.ajax?mode=grid&max=60&min=0&sort=newest

Thanks. 谢谢。

Should be something like this: 应该是这样的:

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;

If URL is reused from the previous one than you might need to replace u.pathname with a fixed path. 如果要从前一个URL重用URL,则可能需要用固定路径替换u.pathname。 Otherwise you keep on adding to it. 否则,您将继续添加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM