以下のスクリプトは、$.post() 応答にエラーがある場合に URL を生成します。生成された URL に関数をアタッチできるように .on() を使用しようとしていますが、機能しません。URL を ($.post なしで) DOM に追加すると、それは魅力のように機能します。URL が $.post() 内で生成された場合は機能したくありません。どうすればそれを機能させることができるかについてのアイデアや解決策はありますか?
// Do the database check:
$.post("test.php",{searchFor : search},function(data) {
if(data.response == true) {
// DO SOME STUFF
} else if(data.response == false && data.error == "noDoc") {
$("#resultsTable").html("<tr><td colspan='6'><p><strong>No user found, <a href='#' class='addDoctor'>Click here</a> to add a doctor.</strong></p></tr>");
} else {
$("#resultsTable").html("<tr><td colspan='6'><p><strong>"+data.error+"</strong></p></tr>");
}
});
});
$(".addDoctor").on("click",function() {
alert("test");
return false;
});