0

I assign the following to a button on a modal. When the user clicks on the button it calls submitHandler.

   var btn = {
        'Submit & Close': function (win) {
            var rc = submitHandler(oLink.$link, $modal);
            $('#createLink').prop('disabled', false);
        },
        'Close': function (win) {
            $modal.closeModal();
            $('#createLink').prop('disabled', false);
        }
    }

My submitHandler looks like this:

    function submitHandler($link, $modal) {

  if (!$form.valid || $form.valid()) {
        $submitBt.disableBt();
        $modal.removeBlockMessages()
            .blockMessage('Contacting Server, please wait ... ', { type: 'loading' });
        $.ajax({
            url: oSubmit.href,
            dataType: 'json',
            type: 'POST',
            data: $form.serializeArray()
        })
        .done(function (json, textStatus, XMLHttpRequest) {
            json = json || {};
            if (json.success) {
                submitSuccessModal(oSubmit, json);
                return true;
            } else {
                submitFailModal(oSubmit, json);
                return false;
            }
            return false;
        })

    }

When I check in the debugger submitHandler runs but when I look at the value of rc it is undefined.

Is there something obvious I am missing. I simply cannot get rc to equal anything other than "undefined".

Update:

I added in an actual section of the code. I am wondering if it could be the ajax call that's causing this? Note that I can follow the code with the debugger to the return true; line.

4
  • Could it be the : instead of the ;? Commented Aug 21, 2012 at 16:12
  • Is the : a typo in the question? Commented Aug 21, 2012 at 16:12
  • Sorry that was a type. The actual code has a semicolon. Commented Aug 21, 2012 at 16:30
  • possible duplicate of Return value from ajax call? see SLaks' answer (do not use async: false). Commented Aug 21, 2012 at 17:55

2 Answers 2

5

Statements are terminated with semicolon, not colon.

function submitHandler($link, $modal) {
   return true;
}          // ↑
Sign up to request clarification or add additional context in comments.

5 Comments

How did you type in your post? +1 for quick find.
Sorry. That was a type. My actual code does use a semicolon. I am totally confused as to why it might not work.
@Vega fileformat.info/info/unicode/char/2191/index.htm or just type ↑ in a non-code block, then Ctrl-C Ctrl-V.
@MattBall Thanks..Also the OP question is about async return value from ajax call.
@Vega yes, it's the typical "ajax is asynchronous problem," looking for a dup to close as.
2

Check the semicolon at the end of the return statement in the handler.

function submitHandler($link, $modal) {
   return true;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.