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

2 回答 2

5

Statements are terminated with semicolon, not colon.

function submitHandler($link, $modal) {
   return true;
}          // ↑
于 2012-08-21T16:11:59.407 回答
2

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

function submitHandler($link, $modal) {
   return true;
}
于 2012-08-21T16:12:37.547 回答