您必须使用回调函数。请尝试以下操作:
$(function() { // I think doAjax should doAnAjax() // here you're passing callback // but you're not using it doAnAjax() doAnAjax(Url, data, function(myRtn) { if (myRtnV == "success") { resetForm($('#myForm')); resetForm($('form[name=addChlGrp]')); } else { $('.rtnMsg').html("Opps! Ajax Error"); } });});// pass callback as third parameter to doAnAjax()function doAnAjax(newUrl, data, callBack) { $.ajax({ url: newUrl, async: true, dataType: 'html', beforeSend: function() { $('.rtnMsg').html("<img src=https://www.mshxw.com/skin/sinaskin/image/nopic.gif"); }, type: "GET", data: data, cache: false, success: function(data, textStatus, xhr) { $('.rtnMsg').html(data); myRtnA = "Success" return callBack( myRtnA ); // return callBack() with myRtna }, error: function(xhr, textStatus, errorThrown) { $('.rtnMsg').html("opps: " + textStatus + " : " + errorThrown); myRtnA = "Error" return callBack ( myRtnA ); // return callBack() with myRtna } });


