Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I am trying to fire off a javascript method using the OnBegin AjaxOption in an Ajax method.

However, when debugging with firebug the callback in unable to find the Javascript method and I do not know why.

My code is simple, first I use a basic Ajax method like this:

<%= Ajax.ActionLink("Testing", "Testing", new AjaxOptions { OnBegin = "RunThisThing" }) %>

Then under it I decalre this script.

    <script type="text/javascript">

        function RunThisThing {
            alert("WORK")
        }
    </script>

Yet when I try running the page and clicking on the link, Firebug tells me "RunThisThing is not defined".

Any idea what I might be doing wrong?

share|improve this question

1 Answer 1

You have a few bugs in your JavaScript code:

  1. You are missing the brackets () after your function name in it's definition.
  2. You are missing the semicolon on your alert statement.

This is how your JavaScript block should appear :

<script type="text/javascript">
  function RunThisThing() {
    alert("WORK");
  }
</script>
share|improve this answer
1  
I think you are not right with point 3. As far as I know the OnBegin attribute receives either the name of a function (so without brackets) or inline code (such as a function call with brackets). So both will work but your suggestion will more likely result in an additional anonymous function which executes your inline code. – Alex Lawrence Jan 7 '12 at 14:33
    
Update: Although both ways would work your suggestion would make it impossible to receive the arguments given to the OnBegin callback unless you pass them explicitly again. – Alex Lawrence Jan 7 '12 at 14:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.