Reputation: 14088
Hi regarding https://github.com/shichuan/javascript-patterns/blob/master/general-patterns/function-declarations.html I define my JS function like this
<script language="javascript">
var clearMessage = function ClearMessage() {
$("#result").html("");
};
</script>
And I try to call it in OnBegin method from MVC ajax,
@using (Ajax.BeginForm(new AjaxOptions() { HttpMethod = "post", OnBegin = "ClearMessage" }))
But I getting error that function not exit, how to call my function that described by this best practice ? (without var clearMessage evering working correct)
Upvotes: 0
Views: 3368
Reputation: 1038780
Never seen such syntax. Don't even know if it is valid javascript.
Try defining your function like this:
<script type="text/javascript">
var ClearMessage = function() {
$("#result").html("");
};
</script>
or like this (which is pretty much the same):
<script type="text/javascript">
function ClearMessage() {
$("#result").html("");
};
</script>
Upvotes: 2