我想在ajax調用成功後啓動一個函數。我現在做的是成功後啓動下一個功能
function ajaxCall(url, types, next) {
$.ajax({
url: url,
type: 'POST',
beforeSend: function() {
$("#plaatsMelding").append("<div id=\"" + types + "verwerkt\"><div class=\"progress-label\">" + types + " verwerken...</div></div>");
},
success: function (data) {
$('#plaatsMelding').empty();
$("#plaatsMelding").append("<div id=\"" + types + "verwerkt\"><div class=\"progress-label\">" + data + "</div></div>");
//run next script
if (next.length) {
alert(next);
next(); //this won't work because it will search for the next() function
}
}
});
}
我開始這個功能使用此功能:
function saveRace() {
ajaxCall("verwerkRace.php", "race", "savePlayers");
}
所以當該功能好了,我希望它運行功能「savePlayers」。我怎樣才能做到這一點?
function savePlayers() {
ajaxCall("verwerkPlayers.php", "players");
}
都好,但我會建議在'next'上進行'typeof'驗證以防止出現錯誤。 – Fluidbyte