onclickのテキストを置き換え、ロードして最終テキストに置き換えたいだけです:
$("#rebuild").click(function(){
$("#rebuild").replaceWith("in progress...").load("/rebuild").replaceWith("end !");
});
/rebuild スクリプトは正しくロードされていますが、最終的な置換が表示されません...なぜですか?
onclickのテキストを置き換え、ロードして最終テキストに置き換えたいだけです:
$("#rebuild").click(function(){
$("#rebuild").replaceWith("in progress...").load("/rebuild").replaceWith("end !");
});
/rebuild スクリプトは正しくロードされていますが、最終的な置換が表示されません...なぜですか?
load
非同期の ajax メソッドです。これは、replaceWith
サーバーからのデータが要素に配置される前に最終的に発生することを意味します。同じ要素での連鎖replaceWith
はせいぜい不安定です。一度置き換えられると存在しなくなり、次の要素がないためです。replace
の完全なコールバックを使用する必要がある後に置き換えたい場合'load
$("#rebuild").click(function () {
$(this).html("in progress...").load("/rebuild", function () {
setTimeout(function(){
$(this).html( "end !");
}, 2000)
})
});
を使用setTimeout
して最終的な変更を行ったので、瞬間的ではないか、負荷全体が意味をなさない. html()
要素はreplaceWith
まだ存在し、その内容のみが変更されます。
Load は、関数が完了すると、関数の引数も受け入れます。
$("#rebuild").click(function(){
$("#rebuild").replaceWith("in progress...").load("/rebuild", function(){
$(this).replaceWith("end !");
});
});
編集:ダーン、誰かが私を打ち負かしました:P