2

In REST API when I pass a value with &(ex: India & China), it throws error and when I checked it in browser it shows &amnp; in place of &.

https://test/_api/web/lists/GetByTitle('Team')/Items?$filter=(Title eq 'India & China')

What shall I do to fix this?

4
  • You are missing to close the value in the end. ('). Commented Jan 14, 2016 at 8:48
  • 1
    Try use encodeURI() on your value (see sharepoint.stackexchange.com/questions/164673/…) Commented Jan 14, 2016 at 8:51
  • Any help from my answer? @vikashkumar Commented Jan 18, 2016 at 4:42
  • yes, but it was not working by directly putting it to the url so I have taken a variable to store encodeURIComponent("India & China")+"') and then I added it to url. Commented Jan 18, 2016 at 5:50

1 Answer 1

6

You need to use encodeURIComponent() not encodeURI()

Query Url should look like

/_api/web/lists/GetByTitle('Team')/Items?$filter=(Title eq '"+encodeURIComponent("India & China")+"')

encodeURIComponent() vs encodeURI()

If list name contains any special character like /, ?, :, @, &, =, +, $ or #, then use encodeURI().

In $filter always use encodeURIComponent().

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.