-1

I have many parameters that I would like to save in the param variable and add it to the url.

How to save this parameter filter% 5Binprogress% 5D = true in the variable param?. I did not have problem with expand --> expand: track

In tab network return --> "https://spotify?expand=track&filter%255Binprogress%255D=true"

should be --> "https://spotify?expand=track&filter%5Binprogress%5D=true"

%255D ---> should be %5D

const param = {
    expand: track,
    'filter%5Binprogress%5D': true  //problem here
}


axios({
    url: "https://spotify?expand=track&filter%5Binprogress%5D=true",
    method: "GET",
    headers: {
        'Authorization': .....
    },
    param: param
})
9
  • 1
    expand is a valid identifier, why would it have a problem? This is a very basic JS error, unrelated to React, Axios or even HTTP: invalid identifiers need quoting as object property names. Commented Jun 25, 2019 at 7:41
  • Is the record filter% 5Binprogress% 5D: true correct? Commented Jun 25, 2019 at 7:44
  • No, it's not, that's why you're getting an error. See e.g. stackoverflow.com/q/4348478/3001761 for explanation. Commented Jun 25, 2019 at 7:46
  • wait, bad dupe. Didn't read it correctly... Commented Jun 25, 2019 at 7:47
  • I guess stackoverflow.com/questions/4348478/… is the correct one. I can't find a question specifically for "what are valid property names". There is this question which is close but still a dupe to the previous one. Commented Jun 25, 2019 at 7:51

2 Answers 2

0

It's because you have a special character in object property.

Try using quotation (single or double)

const param = {
    expand: track,
    "filter%5Binprogress%5D": true
}


axios({
    url: "https://spotify?expand=track&filter%5Binprogress%5D=true",
    method: "GET",
    headers: {
        'Authorization': .....
    },
    param: param
})


Sign up to request clarification or add additional context in comments.

Comments

-2

Either use quotes or use the bracket notation.

const param = {
    expand: track
}

param['filter%5Binprogress%5D'] = true;

Or using quotes:

const param = {
        expand: track,
        "filter%5Binprogress%5D": true 

    }

2 Comments

{ 'filter%5Binprogress%5D': true } is a valid object literal.
Yes - edited the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.