$(document).ready(function() { $('#country_code').change(function(){ CALC.getWeightShippingPHP($(this).val()); }); $('.country').click(function(){ CALC.getWeightShippingPHP('CN'); }); }); var CALC = { getWeightShipping: function (country_code) { $.ajax({ type: "POST", url: "/main/class_func/apiWeightShipping.php?" + Math.random(), dataType: "json", cache : false, async:false, timeout: 30000, data: { "country_code": country_code }, error: function(request, status, error) { alert("code:" + request.status + "\r\nmessage: "+request.reponseText); }, success: function(response, status, request){ // var aResultData = jQuery.parseJSON(response['Data']); if (response == '') { response = 0; } console.log('response : ' + response); // ÇÒÀÎ var disc = (toNumber($('input[name=pay_disc]').val(), 2)); // »óǰ ÃÑÇÕ var price = (toNumber($('input[name=pay_price]').val(), 2)); // ȯÀü ¼ö¼ö·á var bank_trans = (toNumber($('input[name=ibankTransfer]').val(), 2)); // ±âº» ¹è¼Ûºñ var tranc = (toNumber($('input[name=pay_tranc_basic]').val(), 2)); // Ãß°¡ ¹«°Ô ¹è¼Ûºñ var add_tranc = (toNumber(response, 2)); var total_amount = (toNumber( (price - disc ) + tranc + add_tranc + bank_trans , 2)); // ¹è¼Ûºñ ¼öÁ¤ $('input[name=pay_tranc]').val(tranc + add_tranc); $('input[name=pay_add_tranc]').val(add_tranc); // ÃÖÁ¾±Ý¾× º¯°æ $('input[name=pay_amount]').val(total_amount); // Ãâ·Â ºÎºÐ ¼öÁ¤ $('#shipping').html('$' + toNumber(tranc + add_tranc, 2)); $('#grand_total').html('$' + toNumber(total_amount, 2)); console.log('¹è¼Ûºñ ' + $('#shipping').html()); console.log('ÃÑÇÕ°è ' + $('#grand_total').html()); console.log('¹è¼Ûºñ_hide ' + $('input[name=pay_tranc]').val()); console.log('ÃÑÇÕ°è_hide ' + $('input[name=pay_amount]').val()); } }); }, // getWeightShipping : function getWeightShippingPHP: function (country_code) { // ÇÒÀÎ var disc = (toNumber($('input[name=pay_disc]').val(), 2)); // »óǰ ÃÑÇÕ var price = (toNumber($('input[name=pay_price]').val(), 2)); // ȯÀü ¼ö¼ö·á var bank_trans = (toNumber($('input[name=ibankTransfer]').val(), 2)); // ±âº» ¹è¼Ûºñ var tranc = (toNumber($('input[name=pay_tranc_basic]').val(), 2)); $.ajax({ type: "POST", url: "/main/class_func/apiWeightShipping2.php?" + Math.random(), dataType: "json", cache : false, async:false, timeout: 30000, data: { "country_code": country_code, "price": price, "disc": disc, "bank_trans": bank_trans, "tranc": tranc }, error: function(request, status, error) { alert("code:" + request.status + "\r\nmessage: "+request.reponseText); }, success: function(response, status, request){ if (response == '' || response == null || response == undefined) { response = [0,0]; } console.log('response : ' + response); // Ãß°¡ ¹«°Ô ¹è¼Ûºñ var add_tranc = (toNumber(response[0], 2)); var total_amount = (toNumber(response[1], 2)); // ¹è¼Ûºñ ¼öÁ¤ $('input[name=pay_tranc]').val(tranc + add_tranc); $('input[name=pay_add_tranc]').val(add_tranc); // ÃÖÁ¾±Ý¾× º¯°æ $('input[name=pay_amount]').val(total_amount); // Ãâ·Â ºÎºÐ ¼öÁ¤ $('#shipping').html('$' + toNumber(tranc + add_tranc, 2)); $('#grand_total').html('$' + toNumber(total_amount, 2)); console.log('¹è¼Ûºñ ' + $('#shipping').html()); console.log('ÃÑÇÕ°è ' + $('#grand_total').html()); console.log('¹è¼Ûºñ_hide ' + $('input[name=pay_tranc]').val()); console.log('ÃÑÇÕ°è_hide ' + $('input[name=pay_amount]').val()); } }); }, // getWeightShipping : function toNumber : function (num, index) { var dot_index; num = num.toString(); dot_index = num.indexOf('.'); if (dot_index == -1) { return parseFloat(num); } else { return parseFloat(num.substr(0,dot_index+index+1)); } } };