出来上がったクラスを作ったのですが、1回でもいいのに3回もDOMに浸しているので効率が悪いと思います。このために残りのコードを見る必要はないと思うので、整理するために非効率的な部分だけを投稿します。
function showSelectedAttr(){
var productID = <?php echo $product_info['products_id'];?>;
var sizeID = 0;
var tallID = 0;
var colID = 0;
$(".sizeopt").each(function() {
if ($(this).is(':checked')) sizeID = $(this).val();
});
$(".tallopt").each(function() {
if ($(this).is(':checked')) tallID = $(this).val();
});
$(".mine_color").each(function() {
if ($(this).is(':checked')) colID = $(this).val();
});
$.ajax({
type: "POST",
url: 'get_product_attribute.php',
data: "product_id="+ productID +"&size_id="+ sizeID,
success: function( response ) {
$("#attr_container").html(response);
}
});
$.ajax({
type: "POST",
url: 'get_product_attribute.php',
data: "product_id="+ productID +"&size_id="+ tallID,
success: function( response ) {
$("#attr_container_tall").html(response);
}
});
$.ajax({
type: "POST",
url: 'get_product_attribute.php',
data: "product_id="+ productID +"&size_id="+ colID,
success: function( response ) {
$("#attr_container_color").html(response);
}
});
}
ご覧のとおり、ajax API は 3 回別々に呼び出されます。これを行うより良い方法はありますか?