I am currently using Jquery and a webservice to retrieve values for an autocomplete textbox. After the values are returned from the web service, I get an alert with "parser error" as the warning. Why is this?
Jquery
$(document).ready(function() {
$.ajax({
type: "POST",
url: "/Service/WSDataService.asmx/GetStates",
dataType: "json",
data: "{}",
contentType: "application/json; charset=utf-8",
success: function(data) {
var datafromServer = data.d.split(":");
$("[id$='txtautofromDB']").autocomplete({
source: datafromServer
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
web service
[WebMethod]
public string GetStates()
{
StringBuilder sbStates = new StringBuilder();
List<string> stringlist = new List<String>();
stringlist.Add("alabama");
stringlist.Add("boston");
stringlist.Add("abernathy");
/*XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/Data/States.xml"));*/
try
{
foreach (string xnl in stringlist)
{
sbStates.AppendFormat("{0}:", xnl);
}
sbStates = sbStates.Remove(sbStates.Length - 1, 1); //Removes the extra ":"
}
catch (Exception ex)
{
string exp = ex.ToString(); //Setup a breakpoint here
//to verify any exceptions raised.
}
return sbStates.ToString();
}