回调概念
1.不直接返回结果
2.在函数的参数中传递回掉函数
3.在回掉中处理返回结果
function callAjax(isPass, id, success, error){ console.log(isPass); $.ajax({ url: "{:U('question/examine')}", type: "POST", data: { pass: isPass, id: id }, dataType: 'json', success: success, error: error }); } callAjax(true, id, function(data){ $('#table-body tr').each(function(){ if($(this).attr('data-id') == id){ $(this).attr('isChecked', true); $(this).find('.changedStatu').text('通过审查'); $(this).css({ 'color': 'green', 'font-weight': 'bolder' }); $('.body-bottom').hide('fast'); selectNextStep(data); } }); isProcessing = false; layer.close(index); }, function(data){ console.log(data); alert('Fail'); layer.close(index); });