私はこのコードを使ってajax呼び出しを送信し、配送税とシステムの注文の合計を再計算します。 ajaxコールがロードされている間、私は配送税と総箱にローディングスピナーを入れました。呼び出しが返ると、3つのフィールドにそれぞれの値の数値が入力されます。唯一の問題は、フェードが完了すると、スピンナーが入力フィールドに戻ってそこにとどまることです。値が返されたら、どうすればそれを消すことができますか?返品後にajaxStart関数が呼び出されました
$("#recalc_btn").click(function(){
//Grab the order number and site ID from the URL
var order_id = getQueryVariable("o");
var site_id = getQueryVariable("s");
$(document)
.ajaxStart(function() {
$('#total_shipping').css("background", "url('http://www.hsi.com.hk/HSI-Net/pages/images/en/share/ajax-loader.gif') no-repeat left center");
$('#total_tax').css("background", "url('http://www.hsi.com.hk/HSI-Net/pages/images/en/share/ajax-loader.gif') no-repeat left center");
$('#order_total').css("background", "url('http://www.hsi.com.hk/HSI-Net/pages/images/en/share/ajax-loader.gif') no-repeat left center");
});
//Make an AJAX call for the updated shipping
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "json",
timeout: 20000,
//Pass the order ID and site ID through post
data: {
'action': 'recalculate_shipping',
'order_id': order_id,
'site_id': site_id
},
//When success is true change the values of shipping and total and make them green
success: function(msg) {
$("#total_shipping").effect("highlight", {color: '#84e779'}, 3000);
$("#total_tax").effect("highlight", {color: '#84e779'}, 3000);
$("#order_total").effect("highlight", {color: '#84e779'}, 3000);
$("#total_shipping").val(msg.shipping);
$("#total_tax").val(msg.tax);
$("#order_total").val(msg.total);
}
});
return false;
});
これはクリックハンドラにあるため、なぜajaxStartが必要ですか?なぜ、これらの要素にCSSクラスを切り替えるだけではないのですか?あなたは現在、ajaxStartのものを持っている場所にそれらを設定して、あなたの成功ハンドラでそれらを切り替えます。 – WillardSolutions
'$(document) .ajaxStart(function(){})'を '.click()'ハンドラに含める目的は何ですか?これは '#recalc_btn'要素の各クリックで複数のハンドラを付けますか? – guest271314
おそらく、私はajaxStartの仕組みについて誤解を抱いているかもしれません。いったんajax呼び出しが完了すると、コードの適用をやめると想定しました。それは正しいとは思われません。 – shoes