Jump to content

RafaelScharf

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

0 Comum

About RafaelScharf

  1. RafaelScharf

    ERRO AJAX NO CODEIGNITER

    Olá, sou inciante em desenvolvimento e estou trabalhando em um sistema de ponto de venda. Quando faço a busca para vincular o cliente na venda ele da erro na requisição Ajax. Quando faço a busca retorna o seguinte erro no console: GET http://localhost/aroeira/distribuidora/emporium/customers/suggestions?term=R&limit=10&_=1569833733307 404 (Not Found) [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. Veja o código da view/default/pos/add.php <?php if ($this->input->get('customer')) {?> if (!localStorage.getItem('positems')) { localStorage.setItem('poscustomer', <?=$this->input->get('customer');?>); } else if (!localStorage.getItem('poscustomer')) { localStorage.setItem('poscustomer', <?=$customer->id;?>); } <?php } else {?> if (!localStorage.getItem('poscustomer')) { localStorage.setItem('poscustomer', <?=$customer->id;?>); } <?php } ?> if (!localStorage.getItem('postax2')) { localStorage.setItem('postax2', <?=$Settings->default_tax_rate2;?>); } $('.select').select2({minimumResultsForSearch: 7}); var cutomers = [{ id: <?=$customer->id;?>, text: '<?=$customer->company == '-' ? $customer->name : $customer->company;?>' }]; $('#poscustomer').val(localStorage.getItem('poscustomer')).select2({ minimumInputLength: 1, data: [], initSelection: function (element, callback) { $.ajax({ type: "get", async: false, url: "<?=site_url('customers/getCustomer')?>/" + $(element).val(), dataType: "json", success: function (data) { callback(data[0]); } }); }, ajax: { url: site.base_url + "customers/suggestions", dataType: 'json', quietMillis: 15, data: function (term, page) { return { term: term, limit: 10 }; }, results: function (data, page) { if (data.results != null) { return {results: data.results}; } else { return {results: [{id: '', text: 'No Match Found'}]}; } } } }); if (KB) { display_keyboards(); var result = false, sct = ''; $('#poscustomer').on('select2-opening', function () { sct = ''; $('.select2-input').addClass('kb-text'); display_keyboards(); $('.select2-input').bind('change.keyboard', function (e, keyboard, el) { if (el && el.value != '' && el.value.length > 0 && sct != el.value) { sct = el.value; } if(!el && sct.length > 0) { $('.select2-input').addClass('select2-active'); $.ajax({ type: "get", async: false, url: "<?=site_url('customers/suggestions')?>/" + sct, dataType: "json", success: function (res) { if (res.results != null) { $('#poscustomer').select2({data: res}).select2('open'); $('.select2-input').removeClass('select2-active'); } else { bootbox.alert('no_match_found'); $('#poscustomer').select2('close'); $('#test').click(); } } }); } }); }); $('#poscustomer').on('select2-close', function () { $('.select2-input').removeClass('kb-text'); $('#test').click(); $('select, .select').select2('destroy'); $('select, .select').select2({minimumResultsForSearch: 7}); }); $(document).bind('click', '#test', function () { var kb = $('#test').keyboard().getkeyboard(); kb.close(); //kb.destroy(); $('#add-item').focus(); }); } Veja o código do controller Costumer/suggestion function suggestions($term = NULL, $limit = NULL) { // $this->sma->checkPermissions('index'); if ($this->input->get('term')) { $term = $this->input->get('term', TRUE); } if (strlen($term) < 1) { return FALSE; } $limit = $this->input->get('limit', TRUE); $rows['results'] = $this->companies_model->getCustomerSuggestions($term, $limit); return $this->sma->send_json($rows); } veja agora a model company_model.php public function getCustomerSuggestions($term, $limit = 10) { $this->db->select("id, (CASE WHEN company = '-' THEN name ELSE CONCAT(company, ' (', name, ')') END) as text", FALSE); $this->db->where(" (id LIKE '%" . $term . "%' OR name LIKE '%" . $term . "%' OR company LIKE '%" . $term . "%' OR email LIKE '%" . $term . "%' OR phone LIKE '%" . $term . "%') "); $q = $this->db->get_where('companies', array('group_name' => 'customer'), $limit); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } } Ja tentei alterar o async: false para async: true e não funcionou.
×

Important Information

Ao usar o fórum, você concorda com nossos Terms of Use.