I have to implement some sort of live search in a project at the university. I have the following code: MVC Action:
[Authorize]
[AcceptVerbs(HttpVerbs.Get)]
[InitializeSimpleMembership]
public JsonResult Search(string term)
{
var data = ... // get matching item
return Json(data, JsonRequestBehavior.AllowGet);
}
Script in View:
$(document).ready(function() {
$("#searchText").keyup(function() {
$.getJSON('/Search/Search', { "term": $(this).val() }, function(result) {
alert(result);
$("#searchText").val(result.d);
});
});
});
The controller action is called and returns the matching objects, but the javascript function is never called, no alert box, nothing. What can do to make this work?