I am trying to pass some text from a textbox to a controller to get JSON results like so
function invokeAction() {
var searchText = $(\"#SearchTextBo
I've had some problems returning json from services and I wasn't getting any calls back. it turned out that the json was malformed and I was able to test that and get those errors by handling the error option of the plain ajax call.
$.ajax({
type: "GET",
url: "Home/Results/",
data: { search: searchText },
dataType: "json",
error: function(xhr, status, error) {
// you may need to handle me if the json is invalid
// this is the ajax object
},
success: function(json){
alert( "Data Returned: " + json);
}
});
You will have to fix your route and replace {id} with {search} in order to get it to bind to the correct parameter - try something like this:
routes.MapRoute("search", "Home/Results/{search}",
new { controller = "Home", action = "Results" });
If you don't want to do that, you can do it like this by specifying the parametername as a standard querystring paramter
$.getJSON("/Home/Results?search=" + searchText,bindresults);
that will fix the binding.