Click here to Skip to main content
15,888,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

This is my input text box:
HTML
<input type="text" name="grade_id[<?php echo $obj->student_id; ?>]"  id="grade_id_<?php echo $obj->student_id; ?>" class="form-control col-md-7 col-xs-6" />


I am not getting the value return by ajax jquery.

Please help, the get_grade_by_makrs function return value as A,B etc.

What I have tried:

JavaScript
var ob_marks = $('#obtain_total_mark_'+student_id).val();
         $.ajax({
           type   : "POST",
           url    : "<?php echo site_url('ajax/get_grade_by_marks'); ?>",
           data   : { ob_marks : ob_marks },
           success: function(data){
           $('#grade_id_'+student_id).val(data);
           }
       });
Posted
Updated 18-Feb-21 1:50am
Comments
20212a 17-Feb-21 15:04pm    
Debug it and make sure your success function is getting hit and make sure that student_id in your success function is what you expect it to be. I don't see you declare student_id anywhere.
nyt1972 17-Feb-21 23:20pm    
Thanks for the reply, if I change the code $('#grade_id_'+student_id).val(data);
to $('#grade_id_'+student_id).val("Test"); it works, which means that data is not getting the value.
Richard Deeming 18-Feb-21 4:02am    
So debug your PHP code. We can't see your code, and we can't access your database, so we have no way of telling you why your code isn't returning the expected value.

1 solution

This is my controller's function Code:
PHP
public function get_grade_by_marks()
    {
        $obmarks = $this->input->post('ob_marks');
        $result=$this->ajax->get_grade_by_marks($obmarks);
        $name = $result->name;
        return $name;       
    }


Changing return with echo solved the issue.

And below is my Model's Function code

PHP
public function get_grade_by_marks($obmarks)
    {
        
       $this->db->select('name');
        $this->db->from('grades');
       // $this->db->where(array($obmarks => 'between mark_from','mark_to'));
      $this->db->where("$obmarks BETWEEN mark_from AND mark_to");
        return $this->db->get()->row();
    }



When I debug it, it return "B" or "A"
 
Share this answer
 
v2

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