在每个ajax请求浏览器上都很慢

时间:2016-08-09 06:25:42

标签: javascript php jquery ajax

我正在开发php中的库存计费应用程序。每个结算都是通过ajax完成的。在每个账单上,都会有多个ajax请求。但我的问题是,在添加了4-5个账单之后,浏览器变得缓慢而缓慢。所以必须在每5张账单后重新加载页面。那么我要做的就是提高性能呢?

我的申请是:http://quarry.quarrysoft.in/index.php/sale_bill_head/before_add

用户名:管理员 密码:密码



// Adding the bill

$('.my_form_post').submit(function(e) {
    
    start_mask();

    var form = $(this);

    // Hiding Submit button to prevent duplicate form submission.
    form.find('input[type=submit]').hide();

    var input = get_my_form_inputs();


    $.post(form.prop('action'), input, function(data) {
        show_my_form_response(data);

        setTimeout(function() {
            // Showing submit button again after ajax response.
            form.find('input[type=submit]').show();
        }, 2000);
        
        stop_mask();
    });

    e.preventDefault();
});

// Getting variables and values to submit the bill
function get_my_form_inputs()
   {

      var TableData = new Array();

      $('#dv_bill .tbl_bill_body > tbody > tr').each(function(row, tr) {
         TableData[row] = {
            "sbb_fk_godowns": $(tr).find('.gdn_id').val(),
            "sbb_fk_items": $(tr).find('.itm_id').val(),
            "sbb_qty": $(tr).find('.qty').val(),
            "sbb_fk_units": $(tr).find('.unt_id').val(),
            "sbb_rate": $(tr).find('.unt_rate').val(),
            "sbb_vat_pcntg": $(tr).find('.tax .vat_pcntg').text(),
            "sbb_vat": $(tr).find('.vat').val(),
            "sbb_cess_pcntg": $(tr).find('.tax .cess_pcntg').text(),
            "sbb_cess": $(tr).find('.cess').val()
         };
      });
      
      

      var additives = new Array();
      $('.tbl_bill_body #adtv .dv_additionals_row').each(function(row, tr) {
         var text = $(this).find('.adtv_txt').val();
         var val = $(this).find('.adtv_val').val();
         additives[row] = {
            "sba_name": text,
            "sba_amount": val
         };
      });



      var deductives = new Array();
      $('.tbl_bill_body #ddtv .dv_additionals_row').each(function(row, tr) {

         var text = $(this).find('.ddtv_txt').val();
         var val = $(this).find('.ddtv_val').val();
         deductives[row] = {
            "sbd_name": text,
            "sbd_amount": val
         };
      });


      var loaders = [];

      //build an array of selected values
      $('#dv_bill .dv_vown_block .loaders :selected').each(function(i, selected) {
         if ($(selected).val())
            loaders[i] = $(selected).val();
      });
     

      var sbh_id, sbh_datetime, sbh_fk_workcentres, sbh_fk_party_destinations, sbh_temp_party, bill_no, sbh_fk_sale_billnumber_tax, sbh_fk_sale_billnumber_notax, sbh_ref_no, sbh_fk_party_vehicles, sbh_fk_vehicles, sbh_temp_vehicle, sbh_rent, sbh_rent_declared, sbh_add_rent, sbh_add_rent_declared, sbh_fk_driver, sbh_legal_driver, sbh_bata, sbh_bata_declared, sbh_add_bata, sbh_add_bata_declared, sbh_driver_wage_option, sbh_loading, sbh_loading_declared, sbh_add_loading, sbh_add_loading_declared, sbh_loading_mode, sbh_loading_mode_declared, sbh_round_off, sbh_round_off_limit, sbh_paid, sbh_remarks, sbh_status, sbh_jq_net_balance, print_on_save = '';

      // Tax type : 1=> Taxable, 2=> Compounted (Non-taxable)
      var taxType = $('#top_head input[name=tax_type]:checked').val();

      // 1=> Existing party, 2=> New (Temporary) party
      var partyType = $('#dv_bill .basic_details input[name=party_type]:checked').val()

      // 1=> our's, 2=> Others, 3=> parties, 4=>temperory vehicle.
      var vhclOwner = $('#dv_bill .dv_vown input[name=vhcl_owner]:checked').val()

      var pty_id = $('#dv_bill .basic_details #pty_id').val();

      sbh_id = $('#dv_bill #bill_head #sbh_id').val(); //Its value should not be altered dynamically.

      var bill_date = $('#dv_bill #bill_head #bill_date').val();
      var bill_time = $('#dv_bill #bill_head #bill_time').val();
      sbh_fk_workcentres = $('#dv_bill .basic_details #wcntr_id').val();



      // If Existing party
      if (partyType == 1)
      {
         sbh_fk_party_destinations = $('#dv_bill .basic_details #pdst_id').val();

         // If parties vehicle.
         if (vhclOwner == 3)
         {
            sbh_fk_party_vehicles = $('#dv_bill .dv_vown_block #vhcl').val();
         }

      }

      // If a temperory party.
      else
      {
         sbh_temp_party = $('#dv_bill .basic_details #tmp_party').val();
      }


      // If our's vehicle
      if (vhclOwner == 1)
      {
         sbh_fk_vehicles = $('#dv_bill .dv_vown_block #vhcl').val();
         sbh_rent = $('#dv_bill .dv_vown_block #rent').val();
         sbh_fk_driver = $('#dv_bill .dv_vown_block #driver').val();
         sbh_bata = $('#dv_bill .dv_vown_block #bata').val();
         sbh_loading = $('#dv_bill .dv_vown_block #ldc').val();
         sbh_loading_mode = $('#dv_bill .dv_vown_block #ld_mode').val();

         if ($('#dv_bill .dv_vown_block #add_rent').prop('checked'))
            sbh_add_rent = 1;
         else
            sbh_add_rent = 2;

         if ($('#dv_bill .dv_vown_block #add_bata').prop('checked'))
            sbh_add_bata = 1;
         else
            sbh_add_bata = 2;

         if ($('#dv_bill .dv_vown_block #add_ldc').prop('checked'))
            sbh_add_loading = 1;
         else
            sbh_add_loading = 2;

      }

      // If others vehcile.
      else if (vhclOwner == 2)
      {
         sbh_fk_vehicles = $('#dv_bill .dv_vown_block #vhcl').val();
         sbh_rent = $('#dv_bill .dv_vown_block #rent').val();

         if ($('#dv_bill .dv_vown_block #add_rent').prop('checked'))
            sbh_add_rent = 1;
         else
            sbh_add_rent = 2;
      }

      // If temperory vehicle
      else if (vhclOwner == 4)
      {
         sbh_temp_vehicle = $('#dv_bill .dv_vown_block #tmp_vhcl').val();
      }

      bill_no = $('#dv_bill #bill_head #bill_no').val();

      sbh_ref_no = $('#dv_bill #bill_head #ref_no').val();
      sbh_round_off = $('#dv_bill .tbl_pay .round_off').val();
      sbh_paid = $('#dv_bill .tbl_pay .paid').val();
      sbh_remarks = $('#dv_bill #tbl_bill_body #remarks').val();
      sbh_status = $('#dv_bill #tbl_bill_body #sbh_status').val();
      print_on_save = $('#print_on_save').prop('checked') ? 1 : 0;

      var input = {
         taxType: taxType,
         additives: additives,
         deductives: deductives,
         partyType: partyType,
         vhclOwner: vhclOwner,
         loaders: loaders,
         sbh_id: sbh_id,
         bill_date: bill_date,
         bill_time: bill_time,
         sbh_fk_workcentres: sbh_fk_workcentres,
         pty_id: pty_id,
         sbh_fk_party_destinations: sbh_fk_party_destinations,
         sbh_temp_party: sbh_temp_party,
         bill_no: bill_no,
         sbh_fk_sale_billnumber_tax: sbh_fk_sale_billnumber_tax,
         sbh_fk_sale_billnumber_notax: sbh_fk_sale_billnumber_notax,
         sbh_ref_no: sbh_ref_no,
         sbh_fk_party_vehicles: sbh_fk_party_vehicles,
         sbh_fk_vehicles: sbh_fk_vehicles,
         sbh_temp_vehicle: sbh_temp_vehicle,
         sbh_rent: sbh_rent,
         sbh_rent_declared: sbh_rent_declared,
         sbh_add_rent: sbh_add_rent,
         sbh_add_rent_declared: sbh_add_rent_declared,
         sbh_fk_driver: sbh_fk_driver,
         sbh_legal_driver: sbh_legal_driver,
         sbh_bata: sbh_bata,
         sbh_bata_declared: sbh_bata_declared,
         sbh_add_bata: sbh_add_bata,
         sbh_add_bata_declared: sbh_add_bata_declared,
         sbh_loading: sbh_loading,
         sbh_loading_declared: sbh_loading_declared,
         sbh_add_loading: sbh_add_loading,
         sbh_add_loading_declared: sbh_add_loading_declared,
         sbh_loading_mode: sbh_loading_mode,
         sbh_loading_mode_declared: sbh_loading_mode_declared,
         sbh_round_off: sbh_round_off,
         sbh_paid: sbh_paid,
         sbh_remarks: sbh_remarks,
         sbh_status: sbh_status,
         bill_body: TableData,
         sbh_jq_net_balance: $('#dv_bill #bill_foot .balance').html(),
         print_on_save: print_on_save
      }

      return input;
   }






// After submit
function show_my_form_response(response)
   {

      //var json = $.parseJSON(response); 
      var response = response.split('--==++==--');

      // If having errors
      if (response[0].length !== 0 && response[0].trim()) //Used trim is to avoide responses that contain only blank spaces.
      {
         $('#dv_bill .notiece_board').html(response[0]);
      }

      // If success.
      else if (response[1] == 1)
      {

         // Refreshing the p_key, because if the action is edit, it will contain values.
         $('#dv_bill #sbh_id').val('');

         var html = '<div id="success_msg">Bill Saved Successfully !</div>';
         $('#dv_bill .notiece_board').html(html);

         // Printing the content
         if ($('#print_on_save').prop('checked'))
            $('#printable_content').html(response[2]);

         // Initializing the bill. This function must be called only after loaded the file js/sale_bill_add.js. (ie:- After the declaration of variables related to the elements (Eg:- var wcntr ,var party, var destination,var vhcl, etc) @ js/sale_bill_add.js
         initBill(false);

         setTimeout(clear_notiece_board, 4000);
      }
   }
&#13;
&#13;
&#13;

&#13;
&#13;
// After add each bill, the page contents will be initialized.
function initBill(nb_flag)
{
    //If the $('.TTool_target') element has class "clock", it will work as digital clock by "js\clock.js". Ie: that is time will be updated in each second.
    $('.TTool_target').addClass('clock');

    load_workcentre();

    wcntr_license.hide();
    party_license.hide();
    vhcl_capacity.hide();

    $('#dv_bill .basic_details input[name=party_type][value=1]').prop('checked', true); // Default party is an existing one.


    // If Taxable bill;
    if ($('#top_head .tax_type:checked').val() == 1)
    {
        // For taxable bill only existing parties are allowed.
        $('#dv_bill .basic_details input[name=party_type][value=1]').prop('checked', true); // Set party type as existing.
        existing_party();

        $('#dv_bill .basic_details input[name=party_type]').closest('tr').hide();
    }
    else
    {
        $('#dv_bill .basic_details input[name=party_type]').closest('tr').show();
    }

    $('#dv_bill #bill_head #bill_no').val('');

    $('#dv_bill #bill_head #ref_no').val('');
    $('#dv_bill .basic_details #pty_id').show();

    $('#dv_bill .basic_details #tmp_party').hide();

    $('#dv_bill .basic_details #pty_id').html('<option value="">No Parties</option>');

    $('#dv_bill .basic_details #pdst_id').html('<option value="">No Destinations</option>');

    $('#dv_bill #party_ob').val('');

    $('#dv_bill #party_cb').html('');

    $('#dv_bill #ob_crdr').html('');

    $('#dv_bill #cb_crdr').html('');

    $('#dv_bill #bill_head #bill_time').val(getCurrentTime(12, true)); // Function described in js/date_helper.js

    // If the current edition supports vehicle
    if ($('#dv_bill #vhcl_owner_edition').val() == 1)
    {
        $('#dv_bill .dv_vown input[name=vhcl_owner][value=1]').prop('checked', true); // Default vehicle ownership is our's.
        ours_vehicle();
    }
    else if ($('#dv_bill #vhcl_owner_edition').val() == 2)
    {
        $('#dv_bill .dv_vown input[name=vhcl_owner][value=4]').prop('checked', true); // temperory vehicle ownership.
        temperoryVehicle();
        $('#dv_bill .dv_vown input[name=vhcl_owner][value=1]').prop('disabled', true);
        $('#dv_bill .dv_vown input[name=vhcl_owner][value=2]').prop('disabled', true);
        $('#dv_bill .dv_vown input[name=vhcl_owner][value=3]').prop('disabled', true);
    }
    else
        alert("Logical Error");
    
    
    
    

    $('#dv_bill .dv_vown_block #rent').val('');

    $('#dv_bill .dv_vown_block #bata').val('');

    $('#dv_bill .dv_vown_block #ldc').val('');

    $('#dv_bill .dv_vown_block #tmp_vhcl').val('');

    get_firm_settings($('#dv_bill .dv_vown_block #ld_mode'), 'LOADING_PAY_MODE');   //  js/main.js;

    $('#dv_bill .bill_settings #all_drivers').prop('disabled', false);

    $('#dv_bill .bill_settings #all_drivers').css('opacity', '1');

    $('#dv_bill .bill_settings #all_loaders').prop('disabled', false);

    $('#dv_bill .bill_settings #all_loaders').css('opacity', '1');

    $('#dv_bill #show_bal').prop("checked", false);

    if (typeof $('.tbl_bill_body .dv_freights').find('#rent_to_add').prop('id') !== "undefined")
    {
        $('#rent_to_add').closest('.dv_freights_row').remove();
    }

    if (typeof $('.tbl_bill_body .dv_freights').find('#bata_to_add').prop('id') !== "undefined")
    {
        $('#bata_to_add').closest('.dv_freights_row').remove();
    }

    if (typeof $('.tbl_bill_body .dv_freights').find('#ldc_to_add').prop('id') !== "undefined")
    {
        $('#ldc_to_add').closest('.dv_freights_row').remove();
    }

    // Setting the default value for nb_flag.
    nb_flag = typeof nb_flag !== 'undefined' ? nb_flag : true;
    if (nb_flag)
        $('#dv_bill .notiece_board').html("");

    $('#dv_bill #tbl_bill_body #remarks').val('');
    reset_table();
    initVariables();

}

function initVariables()
{

    /**
     * If the $('.TTool_target') element has class "clock", it will work as digital clock by "js\clock.js". Ie: that is time will be updated in each second. But in bill edit, it should not change the time or date automatically. So you should remove the class name "clock" from the element to prevent automatic updation of time.
     */
    if ($('#dv_bill #sbh_id').val())
        $('.TTool_target').removeClass('clock');
    
    
    if ($('#dv_bill #vhcl_owner_edition').val() == 2)
    {
        $('#dv_bill .dv_vown input[name=vhcl_owner][value=1]').prop('disabled', true);
        $('#dv_bill .dv_vown input[name=vhcl_owner][value=2]').prop('disabled', true);
        $('#dv_bill .dv_vown input[name=vhcl_owner][value=3]').prop('disabled', true);
    }
    

    // Tax type : 1=> Taxable, 2=> Compounted (Non-taxable)
    tax_type = $('#top_head .tax_type:checked').val();


// Workcentre
    wcntr = $('#dv_bill .basic_details #wcntr_id');

    wcntr_license = $('#dv_bill .basic_details #wrd_id');

    gdn_id = $('#dv_bill .gdn_id');


// Party' Details  
    party = $('#dv_bill .basic_details #pty_id');

    tmp_party = $('#dv_bill .basic_details #tmp_party');

    destination = $('#dv_bill .basic_details #pdst_id');

    party_license = $('#dv_bill .basic_details #pld_id');

    party_ob = $('#dv_bill #party_ob');

    party_cb = $('#dv_bill #party_cb');

    party_type = $('#dv_bill .basic_details input[name=party_type]:checked').val();




// Vehicle's Details	
    vhcl = $('#dv_bill .dv_vown_block #vhcl');

    vhcl_capacity = $('#dv_bill .dv_vown_block #vhcl_capacity');

    tmp_vhcl = $('#dv_bill .dv_vown_block #tmp_vhcl');

    rent = $('#dv_bill .dv_vown_block #rent');

    bata = $('#dv_bill .dv_vown_block #bata');

    ldc = $('#dv_bill .dv_vown_block #ldc');

    add_rent = $('#dv_bill .dv_vown_block #add_rent');

    add_bata = $('#dv_bill .dv_vown_block #add_bata');

    add_ldc = $('#dv_bill .dv_vown_block #add_ldc');

    driver = $('#dv_bill .dv_vown_block #driver');

    loaders = $('#dv_bill .dv_vown_block .loaders');

    ld_mode = $('#dv_bill .dv_vown_block #ld_mode');

    vhcl_ownership = $('#dv_bill .dv_vown input[name=vhcl_owner]:checked').val();


// Bill Settings   
    itmcat_id = $('#dv_bill .bill_settings #itmcat_id');

    itmhd_id = $('#dv_bill .bill_settings #itmhd_id');

    all_drivers_obj = $('#dv_bill .bill_settings #all_drivers');

    all_loaders_obj = $('#dv_bill .bill_settings #all_loaders');

    all_drivers = '';

    all_loaders = '';
}
&#13;
&#13;
&#13;

&#13;
&#13;
// Variables:



// Tax type : 1=> Taxable, 2=> Compounted (Non-taxable)
var tax_type;

// 1=> Existing party, 2=> New (Temperory) party
var party_type;


// 1=> Our's Vehicles, 2=> Other's vehicles, 3=> Parties vehicles, 4=> Temperory vehicles.
var vhcl_ownership;


// If the the action is 'add' bill.
if (!($('#dv_bill #sbh_id').val()))
{
    tax_type = 2; // Default as 'Compounted / Non-taxable'
    $('#top_head input[name=tax_type][value=2]').prop('checked', true);

    party_type = 1; // Default as "Existing party".
    $('#dv_bill .basic_details input[name=party_type][value=1]').prop('checked', true);

    vhcl_ownership = 1; // Default as "Our's Vehicles".
    $('#dv_bill .dv_vown input[name=vhcl_owner][value=1]').prop('checked', true);
}



// Workcentre
var wcntr = $('#dv_bill .basic_details #wcntr_id');

var wcntr_license = $('#dv_bill .basic_details #wrd_id');

var gdn_id = $('#dv_bill .gdn_id');


// Party' Details  
var party = $('#dv_bill .basic_details #pty_id');

var tmp_party = $('#dv_bill .basic_details #tmp_party');

var destination = $('#dv_bill .basic_details #pdst_id');

var party_license = $('#dv_bill .basic_details #pld_id');

var party_ob = $('#dv_bill #party_ob');

var party_cb = $('#dv_bill #party_cb');



// Vehicle's Details	
var vhcl = $('#dv_bill .dv_vown_block #vhcl');

var vhcl_capacity = $('#dv_bill .dv_vown_block #vhcl_capacity');

var tmp_vhcl = $('#dv_bill .dv_vown_block #tmp_vhcl');

var rent = $('#dv_bill .dv_vown_block #rent');

var bata = $('#dv_bill .dv_vown_block #bata');

var ldc = $('#dv_bill .dv_vown_block #ldc');

var add_rent = $('#dv_bill .dv_vown_block #add_rent');

var add_bata = $('#dv_bill .dv_vown_block #add_bata');

var add_ldc = $('#dv_bill .dv_vown_block #add_ldc');

var driver = $('#dv_bill .dv_vown_block #driver');

var loaders = $('#dv_bill .dv_vown_block .loaders');

var ld_mode = $('#dv_bill .dv_vown_block #ld_mode');


// Bill Settings   
var itmcat_id = $('#dv_bill .bill_settings #itmcat_id');

var itmhd_id = $('#dv_bill .bill_settings #itmhd_id');

var all_drivers_obj = $('#dv_bill .bill_settings #all_drivers');

var all_loaders_obj = $('#dv_bill .bill_settings #all_loaders');

var all_drivers = '';// 1 => Show All drivers, 2=>Show only drivers in the selected vehicle (the vhcl_ownership must be 1 or 2))

var all_loaders = '';// 1 => Show All loaders, 2=>Show only loaders in the selected vehicle (the vhcl_ownership must be 1 or 2))
&#13;
&#13;
&#13;

0 个答案:

没有答案