I've tried numerous solutions for this issue, but I'm still unable to make it work. My goal is to invoke a controller method that accepts a parameter and returns a string based on that parameter. Despite using an ajax GET request, the outcome is not as expected.
Below is my controller method:
public class TestController: Controller
{
[HttpGet]
public string GetString(string word)
{
return "Hello from Get" + word;
}
}
And here is my JavaScript code
testFunction();
function testFunction() {
var word = "yay";
$.ajax({
type: "GET",
url: "Test/GetString",
data: {word: word},
success: function (result) {
console.log("Success: " + result);
},
error: function () {
console.log("Failed.");
}
});
}