This is my Webservice responsible to fill the autocompleate:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
[WebMethod]
public List<Farms> GetFarms1()
{
PlaseTableAdapter pta = new PlaseTableAdapter();
PlaseLande.PlaseDataTable pdt = pta.GetData();
List<Farms> farms = new List<Farms>();
foreach (DataRow dr in pdt)
{
string farmName = (string)dr["FARMNAME"];
string farmID = (string)dr["FARMID"];
farms.Add(new Farms(farmID, farmName));
}
return farms;
}
public class Farms
{
public Farms(string farmid, string farmname)
{
FARMID = farmid;
FARMNAME = farmname;
}
public string FARMID { get; set; }
public string FARMNAME { get; set; }
}
}
This is the jquery to get the json data from the webservice
$("#txtFarms").autocomplete("WebService.asmx/GetFarms1", {
dataType: 'json',
parse: function(data) {
var parsed = [];
data = data.Farms;
for (var i = 0; i < data.length; i++) {
parsed[parsed.length] = {
data: data[i],
value: data[i].FARMNAME,
result: data[i].FARMNAME
};
}
return parsed;
},
formatItem: function(item) {
alert(item);
return item.FARMNAME + ' (' + item.FARMID + ')';
}
});
My code isn't workin what am i missing? Tanks for any assistance!