The code below works when searching for any name that does not contain an apostrophe. When you attempt to find someone with an apostrophe in their name it fails (returns error). How can I allow to find people with apostrophes?
function autoComplete() {
$(document).ready(function () {
$(".AutoCompleteClass").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Service/NomineeWebService.asmx/GetMatchingActiveDirectoryUsers",
data: "{ 'SearchCharacters': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
id: item.NomineeUserName,
value: item.NomineeLastNameFirstName + " - " + item.NomineeDomainAndUserName,
data: item
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
delay: 150,
minLength: 3,
select: function (event, ui) {
$('.SelectedUserNameWrapper input[type=hidden]').val(ui.item.id);
}
});
});
$('#AutoCompleteTextBox').keypress(function (event) {
if (event.which == '13') {
alert('test');
$('#AutoCompleteButton').click();
}
I found resolution to this issue, we should replace all "'" with escape characters. Code looks like below
function autoComplete() {
$(document).ready(function () {
$(".AutoCompleteClass").autocomplete({
source: function (request, response) {
request.term = request.term.replace(/'/gi,"\\'"); // replace globally
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With