function name does not exist in the current context is the error it gives me. I want a dynamic ajax call. Why does this happen? I get the handlers are processed server side, but I do not know how to go around this issue.
var getManager = function (functionName, contentDiv) {
console.log("aircraft manager refresh called");
$.ajax({
type: "GET",
url: '@Url.Action(functionName, "AdminTools")',
cache: false,
data: {},
error: function () {
alert("An error occurred.");
},
success: function (data) {
$("#".concat(contentDiv)).html(data);
}
});
}
I highly recommend you don't couple your server-side and client-side code like:
$.ajax({
type: "GET",
url: '@Url.Action(functionName, "AdminTools")', //THIS
It will turn into a maintenance nightmare. Instead:
<div id="#contentDiv" data-url="@Url.Action(functionName, "AdminTools")">
@* content *@
</div>
then
var getManager = function (functionName, contentDiv) {
console.log("aircraft manager refresh called");
var url = contentDiv.data("url");
$.ajax({
type: "GET",
url: url,
// .....
if you decide later to have multiple contentdivs each can have it's own url, and your code is reusable.