0

I'm sending an XMLHttpRequest.

In the open function I want to set some parameters for the request.

req.open('GET', /some/path?someparam=*somevariable*, true)

I want to get someparam to equal the value of a variable, like var somevariable. In fact the variable name might even have the same name as someparam.

How do I get the variable to resolve in this instance?

0

1 Answer 1

1

String concatenation and encodeURIComponent to make sure you are producing a valid URI:

'/some/path?someparam=' + encodeURIComponent(somevariable)

In an ES6 environment you can use template literals:

`/some/path?someparam=${encodeURIComponent(somevariable)}`
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.