B1B
B1B

Reputation: 303

Splitting template literal to multiple lines isn't working

I am trying to split the template literal to multiple lines in an ajax call, but it's not working for me. Here's my code:

ajax.get(`${this.site}/_api/web/items?\
$filter=active eq 1\
$orderby=type,rank`)

When I do this, it doesn't consider the filtering and orderby that I have. I also tried with this:

ajax.get(`${this.site}/_api/web/items?
$filter=active eq 1
$orderby=type,rank`)

The actual URL in my code is actually longer than this, but this is basically what am trying to do.

Upvotes: 0

Views: 1009

Answers (1)

Melvin Abraham
Melvin Abraham

Reputation: 3036

When using multiline template strings, it includes a training newline character, \n in between the string literal which might not be what you want in case of an endpoint. You can just concatenate the string literals like so:

ajax.get(`${this.site}/_api/web/items?` +
    `$filter=active eq 1` +
    `$orderby=type,rank`
)

Upvotes: 2

Related Questions