jquery多处更新处理

阅读更多
function check_type_message(i){
  var ad_index = "#ad_" + i;
  if($("#order_budget").val() != "" && $(ad_index + "_cost_dis_input").val() != "" && $("#order_regional").val() != "" && $(ad_index + "_budget_ratio_dis_input").val() != ""){
    $.ajax({
      url : "<%= check_type_message_orders_path %>",
      type : "POST",
      data : {order_budget: $("#order_budget").val(), budget_ratio: $(ad_index + "_budget_ratio_dis_input").val(), 
              ad_platform: $(ad_index + "_ad_platform").val(),
              ad_type: $(ad_index + "_ad_type").val(), order_regional: $("#order_regional").val(),
              cost_type: $(ad_index + "_cost_type").val(), cost: $(ad_index + "_cost_dis_input").val(),
              discount: $(ad_index + "_discount_dis_input").val(), order_budget_currency: $("#order_budget_currency").val()},
      success : function(data){
        $(ad_index + "_ctr_prediction").text(format_to_numeric(data["ctr_prediction"]) + "%");
        $(ad_index + "_cpm_prediction").text(format_to_numeric(data["cpm_prediction"]));
        $(ad_index + "_cpc_prediction").text(format_to_numeric(data["cpc_prediction"]));
        $(ad_index + "_clicks_prediction").text(format_to_numeric(data["clicks_prediction"]).slice(0, -3));
        $(ad_index + "_show_cpc_prediction").text(format_to_numeric(data["clicks_prediction"]).slice(0, -3));
        $(ad_index + "_impressions_prediction").text(format_to_numeric(data["impressions_prediction"]).slice(0, -3))
        $(ad_index + "_show_cpm_prediction").text(format_to_numeric(data["impressions_prediction"]).slice(0, -3))
        $(ad_index + "_general_price").text(format_to_numeric(data["general_price"]));
        $(ad_index + "_public_price").text(format_to_numeric(data["public_price"]));
        discount_cost_msg(i, data["cost_can"]);
        set_discount_val(i);
      }
    })
  }else{
    if ($("#order_regional").val() != ""){
      $.ajax({
      url : "<%= check_type_message_orders_path %>",
      type : "POST",
      data : {order_budget: $("order_budget").val(), ad_platform: $(ad_index + "_ad_platform").val(),
              budget_ratio: $(ad_index + "_budget_ratio_dis_input").val(),
              ad_type: $(ad_index + "_ad_type").val(), order_regional: $("#order_regional").val(),
              cost_type: $(ad_index + "_cost_type").val(), cost: $(ad_index + "_cost_dis_input").val(),
              discount: $(ad_index + "_discount_dis_input").val(), order_budget_currency: $("#order_budget_currency").val()},
      success : function(data){
        $(ad_index + "_general_price").text(format_to_numeric(data["general_price"]));
        $(ad_index + "_public_price").text(format_to_numeric(data["public_price"]));
        set_discount_val(i);
      }
    })
    }else{
      $(ad_index + "_general_price").text("");
      $(ad_index + "_public_price").text("");
    }
    text_clear = ["ctr_prediction", "cpm_prediction", "cpc_prediction", "clicks_prediction", "show_cpc_prediction", "impressions_prediction", "show_cpm_prediction"]
    $.each(text_clear, function( index, value ) {$(ad_index + "_" + value).text("");});
    $(ad_index + "_check_cost").html("");
  }
  show_cost_type(i);
}

 def check_type_message
    params.delete("action")
    params.delete("controller")
    params.permit!
    @ad = Advertisement.new()
    @ad.attributes = params.permit!
    @ad.discount = (@ad.cost.to_f / @ad.public_price) * 100
    # @ad.discount = params["discount"].to_f / 100 if params["discount"].present?
    # @ad.budget_ratio = params["budget_ratio"].to_f / 100 if params["budget_ratio"].present?
        
    impressions_prediction = @ad.impressions_prediction
    clicks_prediction = @ad.clicks_prediction
    ctr_prediction = @ad.offer.ctr_prediction
    general_price = @ad.general_price
    cpm_prediction = @ad.cpm_prediction
    cpc_prediction = @ad.cpc_prediction
    public_price = @ad.public_price
    
    render :json => {
                :ctr_prediction => ctr_prediction,
                :clicks_prediction => clicks_prediction,
                :impressions_prediction => impressions_prediction,
                :cpm_prediction => cpm_prediction,
                :cpc_prediction => cpc_prediction,
                :general_price => general_price,
                :public_price => public_price,
                :cost_can => @ad.cost_can? }
  end


jquery更新select标签:
function set_ad_platform_by_region(){
  current_region = $("#order_regional").val();
  if($.inArray(current_region, ["US_UK_AU_NZ_MY", "HK_TW_MA_SG", "OTHER_COUNTRY"]) == -1 ){
    options =  "" + "";
  }else{
    options = "";
  }
 $('.adv_ad_platform').each(function(){
    $(this).find('option').remove();
    $(this).append(options);
    $(this).change();
   })
}


$("#chosen_multiple_test").val(["NATION"]).trigger("liszt:updated");

你可能感兴趣的:(jquery多处更新处理)