I'm doing jQuery autocomplete. Works fine if I put hard codded JSON array. But it fails when I pass the array from c#. Please help, I spend enough time with it and I'm stuck!
Here is my jQuery code in AutoComplete.aspx
<script type="text/javascript">
$(document).ready(function () {
var msgbox = $("#status");
$.ajax({
type: "POST",
//Page Name (in which the method should be called) and method name
url: "AutoControl.aspx/GetData",
//else If you don't want to pass any value to server side function leave the data to blank line below
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#status").val(msg.d);
}
});
$('#<%=tags.ClientID%>').autocomplete(["c++", "java", "php", "coldfusion"], {
width: 320,
max: 4,
highlight: false,
multiple: true,
multipleSeparator: " ",
scroll: true,
scrollHeight: 300
});
});
</script>
Here is my C# code in AutoComplete.aspx.cs
[System.Web.Services.WebMethod]
public static string GetData()
{
return "\"c++\", \"java\", \"php\"";
}
How do I pass the JSON array from C# to jQuery. With this code I could retrieve the values from c# but some reason JSON is not reading the values.
I want to change this code: $('#<%=tags.ClientID%>').autocomplete(["c++", "java", "php", "coldfusion"]
to
$('#<%=tags.ClientID%>').autocomplete([ jsonArray_from_C# ]