My code :
var db = Database.Open("dbase");
var term = Request.Form["username"] + "%";
var sql = "SELECT * from Users where Username LIKE @0";
var result = db.Query(sql, term);
var data = result.Select(p => new{label = p.username});
Json.Write(data, Response.Output);
And the form :
<script type="text/javascript">
$(function(){
$('#username').autocomplete({source:'getProducts'});
});
</script>
</head>
<body>
<form method="post">
<label for="username">Enter Username: </label>
<input type="text" name="username" id="username" />
</form>
The problem : This process is ran every time a user types a character into a text box. No matter what character is typed, every single username in the database is returned. I assume the problem lies in my SQL query ?
Can anyone help me with this ?
Use
Request.QueryString["term"]instead ofRequest.Form["username"].This is based on the documentation at http://jqueryui.com/demos/autocomplete/. Look for the quoted string
"term"on that page.