viola123
asked on
How to solve this issue: Autocomplete cannot accept special characters?
Hi all,
i have an autocomplete in my web page, but when i type some special characters such as \ or '
it will popup error.
how to solve this? the autocomplete should accept special characters because user may type any thing in the text area.
thanks a lot
i have an autocomplete in my web page, but when i type some special characters such as \ or '
it will popup error.
how to solve this? the autocomplete should accept special characters because user may type any thing in the text area.
thanks a lot
<script type="text/javascript">
$(function () {
$("#tbComm").autocomplete({
source: function (request, response) {
$.ajax({
url: "Comments.asmx/FetchCommentary",
data: "{'comm': '" + 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 {
value: item.Commentary
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
});
});
*********************
<div class="ui-widget">
<label for="tbComm" style="text-align:left;" >Comments:
</label><br />
<asp:TextBox ID="tbComm" class="field_item" runat="server" TextMode="MultiLine"
Height="120px" Width="377px"></asp:TextBox>
<br />
</div>
*****************************
[WebMethod]
public List<Commentary> FetchCommentary(string comm)
{
var comment = new Commentary();
var fetchComm = comment.GetCommentary()
.Where(m => m.Commentary.ToLower().StartsWith(comm.ToLower()));
return fetchComm.ToList();
}
more infos : http://xkr.us/articles/javascript/encode-compare/
ASKER
hi leakim971:
thanks a lot, i will have a try.
thanks a lot, i will have a try.
ASKER
hi leakim971:
encodeURIComponent() will not encode: ~!*()'
how to solve those special characters: ~!*()'
the user may key in ' or () ! *.
thanks a lot
encodeURIComponent() will not encode: ~!*()'
how to solve those special characters: ~!*()'
the user may key in ' or () ! *.
thanks a lot
try this : data: "{'comm': '" + request.replace(/(\W)/g, function($1) { return "%" + $1.charCodeAt(0).toString( 16); }) + "'}",
ASKER
hi,
i got this error when i try request.replace(/(\W)/g, function($1) { return "%" + $1.charCodeAt(0).toString( 16); })
Microsoft JScript runtime error: Object doesn't support this property or method
i got this error when i try request.replace(/(\W)/g, function($1) { return "%" + $1.charCodeAt(0).toString(
Microsoft JScript runtime error: Object doesn't support this property or method
ASKER
am i missing reference?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
leakim971:
you are star! it works very well.
thanks a lot
viola
you are star! it works very well.
thanks a lot
viola
by : data: "{'comm': '" + encodeURIComponent(request