P.K. P.K. - 7 months ago 36
Javascript Question

how to call Javascript method from MVC4 link (error JavaScript runtime error: Object doesn't support this action)

I have a javascript code which should be started after clicking on link on view page, but the error is displayed. What is wrong?
Error is: '
0x800a01bd - JavaScript runtime error: Object doesn't support this action'

Javascript code:

var MenuController = function () {
};

MenuController.prototype.Logout = function () {

$.ajax({
type: "GET",
url: '/Account/Logout',
success: function (response) {
alert('log out');
window.close();
}
});

};


HTML code:

<a onclick="new MenuController.Logout();" alt="Log out">Log out</a>
</li>
...
<script src="/js/Controller/MenuController.js" type="text/javascript"></script>

Answer

You're missing the brackets to construct the MenuController. new MenuController.Logout(); should become new MenuController().Logout();

Comments