Click here to Skip to main content
15,742,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i have this model function inside my user_model.php, it should wait for a value ($color) that is coming from user clicks on some buttons in a view through controller, how to make it async

public function get_item_options_values($color){

    if($color!== null)
     $this->db->join('category_options', ' = items_options_value.option_id ');
     $this->db->join('items_variations', ' = items_options_value.var_id ');

     $this->db->join('category_options', ' = items_options_value.option_id ');
     $this->db->join('items_variations', ' = items_options_value.var_id ');


     $query = $this->db->get();
     return $query->result();


the controller gets the value coming from view through ajax call

public function show_item(...){
    $color = $this->input->post('color');
    $data['item_options_values'] = $this->user_model->get_item_options_values($color);


looping through some divs and send the value to controller through ajax

colors = document.querySelectorAll('.colors');
sizes = document.querySelectorAll('.sizes');

colors.forEach((c) => {
    c.addEventListener('click', function() {
        color = this.querySelector('.color').getAttribute('data')
            type: "POST",
            url: '<?php echo base_url();?>Home/show_item',
            dataType: 'json',
            data: {
                color: color
            success: function(data) {
                document.querySelectorAll('.sizes').forEach((s) => {
                    console.log(s.querySelector('.size').innerHTML = data);




the code is not working and the value is not being sent

What I have tried:

i've tried to play with script code, it produces a value every on click event, but the data is not being sent, and it alerts "something is wrong"
Updated 8-Sep-21 23:14pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900