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();
}
Kind of quirky, but I ended up doing the replace like this: request.term.replace(“‘”, “%27”)
Then on my web service, I intercept and replace back to using the apostrophe:
SearchCharacters = SearchCharacters.Replace(“%27”, “‘”);
and pass that to my database call.
This works. It is something in the autocomplete plugin or jquery stuff. Since this works, I will use it and move on.
Thanks for all the suggestions. By the way, none of the escaping worked for me…
Thanks again…