0
나는 동적으로 &을 추가 할 수있는 양식을 작성하여 제품을 삭제합니다.제품 선택시 모든 제품의 가격 합계를 받으십시오.
나는 $ 10, $ 20, $ 30의 세 제품을 추가했습니다.
i 임시로 제품을 데이터베이스에 추가하십시오.
지금은 페이지를 새로 고치지 않고 모든 제품의 최종 합계를 원합니다.
$(document).ready(function() {
//##### send add record Ajax request to response.php #########
$("#FormSubmit").click(function (e) {
e.preventDefault();
if($("#fund_amount").val()==='')
{
alert("Please enter amount");
return false;
}
var fund_amount = $("#fund_amount").val();
var fund_category=$("input[name=fundcategory]:checked").val();
var dataString = 'fund_amount='+ fund_amount + '&fund_category=' + fund_category;
jQuery.ajax({
type: "POST", // HTTP method POST or GET
url: "response", //Where to make Ajax calls
dataType:"text", // Data type, HTML, json etc.
data:dataString,
success:function(response){
$("#productholder").append(response);
$("#fund_amount").val(''); //empty text field on successful
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
//##### Send delete Ajax request to response.php #########
$("body").on("click", "#productholder .del_button", function(e) {
e.returnValue = false;
var clickedID = this.id.split('-'); //Split string (Split works as PHP explode)
var DbNumberID = clickedID[1]; //and get number from array
var myData = 'recordToDelete='+ DbNumberID; //build a post data structure
jQuery.ajax({
type: "POST", // HTTP method POST or GET
url: "response", //Where to make Ajax calls
dataType:"text", // Data type, HTML, json etc.
data:myData, //Form variables
success:function(response){
//on success, hide element user wants to delete.
$('#item_'+DbNumberID).fadeOut("slow");
},
error:function (xhr, ajaxOptions, thrownError){
//On error, we alert user
alert(thrownError);
}
});
});
});
..
을 내가 추가 및 삭제했을하지만 난 삭제하거나 제품을 추가 할 때마다 빠른 합계를 원하는 난 u는 그것을 얻을 바랍니다.
당신의 합계는 어디에서이고 또는 당신은 어딘가에 이미'sum' 가치가 있습니까? – Pavlo
db에서 추가 또는 삭제 후 db의 합계를 계산하고 응답의 값을 반환 할 수 있습니다. jquery success : function에 합계를 표시 할 수 있습니다. –