I saw bunch of similar posts on stackoverflow, but neither worked for me. I have simple AJAX ENABLED WCF service, which returns cities based on input
[OperationContract]
public IEnumerable<string> GetCities(string prefix)
{
string[] cities = new[] { "New York", "Atlanta", "Los Angeles", "Las Vegas", "Arizona", "New Hampshire", "New England" };
if(!String.IsNullOrEmpty(prefix))
{
cities = cities.Where(a => a.ToLower().StartsWith(prefix.ToLower())).ToArray();
}
return cities;
}
Now I'm trying to make a call to this method using jquery ui's autocomplete. The problem is I have to pass prefix parameter to the method call, but whatever I'm trying the prefix parameter gets appended to url as a query string. Here's the jQuery code that I have
$("input[type=text][id*=autocompleteBox]").autocomplete({
source: function (request, response) {
var dataCity = {'prefix': request.term};
$.ajax({
url: "http://localhost:1939/Cities.svc/GetCities",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(dataCity),
success: function (data) {
response($.map(data, function (item) {
return {
label: data
}
}));
}
});
},
minLength: 0
});
I know I have 3 options to call remote datasource. First option is the code above, but this way I have stringified json result appended to url.
Then I tried to simply pass url of service to source option, but I got the same result ( term=myinput appended to url ).
I can't use 3rd option ( an array with local data ) as I have many entries, I don't want to keep them all on the client.
So how can I pass prefix parameter to Service Method ? Is this possible, or I have to stuck with url appended parameters if I choose to use jquery ui's autocomplete widget ?