showing results for - "ajax common"
Elon
23 Jun 2020
1// common.js
2var COMMON = {
3    base_url: '',
4    column_cache: '',
5    url_update_cache: '',
6    module_name: '',
7    cfg_lang: '',
8    action_flow: {
9        approve: 'Approve',
10        reject: 'Reject',
11    },
12    
13    call_ajax: function(params){
14        $.ajax({
15            url: params.url,
16            type: params.type,
17            data: params.data,
18            dataType: params.dataType,
19            headers: params.headers,
20            beforeSend: function(){
21
22            },
23            success: params.success,
24            error: params.error,
25            complete: function(){
26
27            }
28        })
29    },
30}
31
32// admin_company_credit.js
33var ADMIN_COMPANY_CREDIT = {
34    url_get_pay_credit_detail_by_company: '',
35    COMMON.call_ajax({
36      url: ADMIN_COMPANY_CREDIT.url_get_pay_credit_detail_by_company,
37      type: 'POST',
38      data: {
39        company_id: $('#company_id').val(), // params here
40      },
41      dataType: 'json',
42
43      success: function(result) {
44        if (result.status) {
45           // succed here
46        }
47
48      },
49
50      error: function(error) {
51        console.log("error message here")
52      }
53    });
54}
55
56// using 
57
58<?php  // cakephp
59	echo $this->Html->script('CakeAdminLTE/pages/admin_company_credit.js?v=' . date('U'), array('inline' => false));
60?>
61
62<script type="text/javascript">
63	$(document).ready(function(){
64		ADMIN_COMPANY_CREDIT.url_get_pay_credit_detail_by_company 	= '<?= Router::url(array('plugin' => 'company', 'controller' => 'company_credits', 'action' => 'get_pay_credit_detail_by_company')); ?>';
65		ADMIN_COMPANY_CREDIT.init_page();
66	});
67</script>