CodeIgniter Forums

Full Version: pop up window not getting post value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
<button class="btn btn-sm btn-info" onclick="edit_book1(<?php echo $row['markid'];?>)"><i class="fa fa-search"></i></button>


function edit_book1(markid)
    {
      save_method = 'update';
      $('#form1')[0].reset(); // reset form on modals

      //Ajax Load data from ajax
      $.ajax({
        url : "<?php echo site_url('/Users/ajax_edit')?>/" + markid,
        type: "POST",
        dataType: "JSON",
        success: function(data)
        {

            $('[name="markid"]').val(data.markid);
           // $('[name="sel_ass"]').val(data.ass);
           
            
            $('#modal_form').modal('show'); // show bootstrap modal when complete loaded
            $('.modal-title').text('Upload'); // Set title to Bootstrap modal title

        },
        error: function (jqXHR, textStatus, errorThrown)
        {
            alert('Error get data from ajax');
        }
    });
    }

public function ajax_edit1($markid)
    {
      $data = $this->User_model->get_by_id1($markid);
     // $data = $this->User_model->get_by_id1($markid);

     echo json_encode($data);
    }

public function get_by_id1($markid)
    {
        $response = array();
        $this->db->select('*');                 
        $this->db->from('upload'); 
        $this->db->where ('markid',$markid);        
        $query = $this->db->get();
       return $query->result_array();  

    }

Error get data from ajax. kindly solve my problem
You need to use Chrome Developer Tools to see what AJAX request is getting back.

It could be routing issue, you might be sending more info than just JSON (for example, output profiler HTML), or you might have to set return content header to say it is JSON content.
(09-04-2018, 02:32 AM)Pertti Wrote: [ -> ]You need to use Chrome Developer Tools to see what AJAX request is getting back.

It could be routing issue, you might be sending more info than just JSON (for example, output profiler HTML), or you might have to set return content header to say it is JSON content.

XHR request=xhr
Hes' posting json and passing it right to the model, he needs to decode the json first.
(09-04-2018, 04:46 AM)InsiteFX Wrote: [ -> ]Hes' posting json and passing it right to the model, he needs to decode the json first.

The JS doesn't seem to POST any data, just URL, which should work form CI point of view.

Seems like browser side issue pre AJAX call, or result isn't pure JSON, these would be the two things I'd check first.
He's also adding a / to the site_url which applies it.

He needs to remove the / off of Users and Users should be all lower case.
(09-04-2018, 01:13 PM)InsiteFX Wrote: [ -> ]He's also adding a / to the site_url which applies it.

That's true too, mate of mine struggled with trailing slash on AJAX calls for so long. Took a while to figure out.
Use row_array() in your model, not result_array(), since you only need to get one record.
PHP Code:
public function get_by_id1($markid)
{
 
   //$response = array();   // this line makes no sense
 
   $query $this->db->where('markid',$markid)->get('upload');
 
   return $query->row_array();