小编use*_*820的帖子

使用jQuery在页面加载时将字符串添加到url?

我正在尝试在页面加载时将此特定字符串添加到我的URL的末尾:

?aa_campaign = f45632

(http://examplesite.com/test.html)

它用于营销和跟踪.

我试过这个:

if window.location.href.indexOf("http://examplesite.com/test.html") {
  window.location = "http://examplesite.com/test.html?aa_campaign=f45632";
}
Run Code Online (Sandbox Code Playgroud)

直接上升不起作用,但这个想法是我正在寻找的.有什么想法吗?

javascript url jquery

7
推荐指数
1
解决办法
8897
查看次数

同时获取多个 URL?

我正在寻找一种同时获取多个 URL 的方法。据我所知,API 只能通过单个产品查找来检索我想要的数据,因此我需要使用 url 结构“/products/productID/”一次获取多个产品。注意,这是在 VUEJS 中。这是我的代码到目前为止的样子:

在我的 productServices.js 中:

const productsService = {
 getCategory(productID){
    const url = `${config.apiRoot}/products/${productID}`

    return fetch(url, {
    method: 'GET',
    headers: {
        'content-type': 'application/json',
        'Authorization': `Bearer ${authService.getToken()}`
    },
    })
 }
}
Run Code Online (Sandbox Code Playgroud)

在我看来:

data() {
  return {
    featuredProduct: [13,14,15],
    productName: [],
    productImg: []
  }
}
Run Code Online (Sandbox Code Playgroud)
async mounted(){
    const response = await productsService.getCategory(this.featuredProduct)
    const resJSON = JSON.parse(response._bodyInit)
    this.loading = false
    this.productName = resJSON.name
    this.productImg  = resJSON.custom_attributes[0].value
}
Run Code Online (Sandbox Code Playgroud)

所以我需要点击所有三个特色产品 ID 并存储数据。我不太确定如何遍历多个 URL。我所有的其他 API 调用都可以使用搜索参数轻松获得所有数据,但对于我在此处需要的特定数据(产品图片),只能通过调用单个产品来查看。

任何帮助深表感谢!

javascript fetch vue.js

5
推荐指数
2
解决办法
7295
查看次数

如何htaccess 301重定向网址中带有问号的网页

我正在尝试重定向几个在URL中都有问号的页面.

我基本上想要重定向:

www.example.com/?attachment_id=456 to www.example.com
Run Code Online (Sandbox Code Playgroud)

还有很多页面都有不同的ID#.

我在htaccess尝试了一些没有运气的东西..

有任何想法吗?

这是我试过的:

RewriteCond %{QUERY_STRING} ^attachment_id=[0-9]
RewriteRule ^/$ http://www.example.com/? [L,NC,R=301]
Run Code Online (Sandbox Code Playgroud)

html regex apache .htaccess mod-rewrite

3
推荐指数
1
解决办法
1226
查看次数

在JavaScript中为每个列表项迭代一个aray

我正在使用一个我无法控制HTML的电子商务页面.我正在尝试为每个列表项(swatch)添加价格.

   // This is some hidden HTML being displayed on the page that has altered prices in it.

   const superAttributesRaw = [...document.querySelectorAll('.super-attribute-select option')];
   const superAttributes = superAttributesRaw.filter(newValue => Object.keys(newValue).length !== 0);

   // This is the shown HTML swatch I need to add the altered prices to.

   const swatchUl = [...document.querySelectorAll('.swatchesContainer ul li')];

   // Pulling out the altered prices and putting them into an array.

   prices = [];
   for (let value of superAttributes) {
       prices.push(value.config.price);
   }

   // This adds the sample …
Run Code Online (Sandbox Code Playgroud)

javascript arrays loops

1
推荐指数
1
解决办法
77
查看次数

在Sublime Text中查找并替换网址中的所有数字

我正在编辑sql数据库,需要查找和替换以下内容。

/imagename-1.jpeg
Run Code Online (Sandbox Code Playgroud)

至:

/imagename.jpg
Run Code Online (Sandbox Code Playgroud)

一直到

/imagename-867.jpeg
Run Code Online (Sandbox Code Playgroud)

我希望RegEx有办法做到这一点,有什么想法吗?

谢谢

regex sublimetext2

-2
推荐指数
1
解决办法
3337
查看次数