Okay, so JQuery's autocomplete widget is driving me nutz!
I have tried numerous ways of loading the widget. I am currently getting the following:
Error: jQuery15105511000803127266_1353087819681 was not called - parsererror
and the Response value (from firebug) appears to be System.string[] though I'm not sure if it's an a string who's value is System.string[] or an actual system.string[] object.
Am I just being stupid, or am I missing something (please be kind in your answer to that last question...)?
My javascript is:
$("#clientName").autocomplete({
source: function (request, response) {
$.ajax({
url: "/supplier/apSupplierSearch/",
data: { searchAPName: clientName.value },
dataType: "json",
type: "POST",
success: function (data) {
//response(data);
response($.map(data, function (item) {
return {
label: item.Name,
value: item.Name
}
}))
}
}); // ajax
}, // function [{
scroll: true,
scrollHeight: 600,
minLength: 4
});
My WebMethod is:
[WebMethod]
public string[] apSupplierSearch(string searchAPName)
{
IList<int> selectedPropertyIDs = new List<int>();
string currentRole = UserServices.GetCurrentRole();
Property currentProperty = UserServices.GetCurrentPropety();
List<ApSupplier> suppliers = ApSupplierQueries.GetApSuppliers(searchAPName, selectedPropertyIDs, currentRole, currentProperty);
List<string> supplierList = new List<string>();
foreach (ApSupplier supplier in suppliers)
{
supplierList.Add(supplier.Name);
}
return supplierList.ToArray();
}
I'm not too familiar with C# but you probably want to print the supplier list rather than return it. When doing AJAX, you acutally have to output data, not just return it from a method (but that could be my misunderstanding of the language).
Secondly, you need to use a library to create a JSON string from the array created from toArray(). Otherwise, jQuery doesn't recognize the response as JSON and won't parse it.
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