With script below, request to the server always sends empty string (even if value is not emtpty), where the data line is:
data: "{ 'folderName': '" + $(this).val() + "' }"
The html element under investigation is this:
<asp:TextBox id="searcher" runat="server" ClientIDMode="Static" CssClass="classificationFolder" />
Script is:
<script type="text/javascript">
$(document).ready(function () {
$(".classificationFolder").each(function () {
$(this).autocomplete({
source: function (request, response) {
$.ajax({
url: "Services/svcFolder.asmx/SearchFolders",
data: "{ 'folderName': '" + $(this).val() + "' }",
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.Name,
label: item.Name + " " + item.Type
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.responseText);
}
});
},
minLength: 2,
});
})
});
The reason that I select elements by css class selector ($(".classificationFolder")) is that, this control is a user control and used in the same page more than once. That is why I'm not using $("#searcher").
I tested the code In IE8 and Chrome 8.0.552.28 beta. This issue is arising in both of the browsers.
On the other hand, request is sent to the server, client received response successfuly and response is processed on the client.
So anyone has any idea why $(this).val() always returns empty string?