I created a class for JSON responses:
public class PostCodeJson
{
public String Text { get; private set; }
public String Value { get; private set; }
#region Constructors
/// <summary>
/// Empty constructor
/// </summary>
public PostCodeJson()
{
this.Text = String.Empty;
this.Value = String.Empty;
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="_text"></param>
/// <param name="_value"></param>
public PostCodeJson(String _text, String _value)
{
this.Text = _text;
this.Value = _value;
}
#endregion Constructors
}
and function returns list of this class using in webservices method:
[WebMethod]
public List<PostCodeJson> GetPostCodesCompletionListJson(String prefixText, Int32 count)
{
return LibDataAccess.DBServices.PostCodes.GetPostCodeJson(prefixText, count);
}
And in aspx i do this that:
<script>
$(document).ready(function() {
$("#<%=pc.ClientID %>").autocomplete(
baseUrl + "WebServices/Autocomplete.asmx/GetPostCodesCompletionListJson",
{
parse: function(data) {
var array = new Array();
for (var i = 0; i < data.length; i++) {
var datum = data[i];
var name = datum.Text;
var display = name;
array[array.length] = { data: datum, value: display, result: datum.Value };
}
return array;
},
dataType: "xml"
});
});
</script>
and when you enter something in the box i got an error: Request format is unrecognized for URL unexpectedly ending in '/GetPostCodesCompletionListJson
What am I doing wrong??
I solve this problem:
in in web.config
But i get next problem: how to provide input parameters