I am trying to write a JQuery AutoComplete search( I am new to both WCF and JQurey), the search result should be start with the text I put in the text box which is txtProjectID
here is my JQurey code
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Invoking the Project Service</title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/ui.core.1.7.2.js" type="text/javascript"></script>
<script src="Scripts/jquery.autocomplete.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.css" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
var json = JSON.stringify({ "searchBy":"ame" }); //I even hard code the value here as "ame"
$("#txtProjectID").autocomplete(
"MySeriveAddress/WCFBasics/WCFBasics/NewProjectService.svc/GetOptions", {
dataType: "json",
minChars: 3,
type: "POST",
contentType: "application/json; charset=utf-8",
//data: "{'searchBy': "' + $('#txtProjectID).val() + '"}',
//data: '{"searchBy": "ame"}',
data: json,
parse: function(data) {
var items = data.d;
var parsed = [];
for (var i = 0; i < items.length; i++)
parsed[i] =
{
data: items[i],
value: items[i].ProjectID,
result: items[i].ProjectName
};
return parsed;
},
formatItem: function(row, i, n)
{
return row.ProjectName + "<br/>" + "Id:" + row.ProjectID + " Name:" + row.ProjectName;
},
width: 300,
mustMatch: true,
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtProjectID" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
this is my WCF Service Web method, pretty straight forward.
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
public Project[] GetOptions(string searchBy)
{
//return new[] { "xxxx", "yyyy", "zzzz" };
List<Project> Projects = new List<Project>();
//fill my project list here
return Projects.ToArray();
}
But I couldn't get my "searchBy" parameter value passed to the WCF service method, every time is null even I hard code the data part, Am I missing anything here.