tags:

views:

30

answers:

1

I am using OData to query my database. The following line of code works fine when “adapterName” just contains text.

ds.query('/DataAdapters?$filter=Name eq \'' + adapterName + '\'', ifmgr_CreateAdapter_Step1, onGenericFailure, '');

If “adapterName” contains a single quote it fails. I tried escaping the single quote by using the following code:

adapterName = adapterName.replace(/\'/g, '\\\'');

Although this correctly escapes the user defined text the function still fails. Can anyone tell me what the correct format is for text in the query?

A: 

If you need a single quote as part of the value and it's also a delimeter. Then instead of replacing a single quote with the \' version replace it with %27. This the URL escaped version of a single quote.

JaredPar