CodeIgniter Forums
pop up window not getting post value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forum-1.html)
+--- Forum: Lounge (https://forum.codeigniter.com/forum-3.html)
+--- Thread: pop up window not getting post value (/thread-71606.html)



pop up window not getting post value - kvanaraj - 09-03-2018

<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


RE: pop up window not getting post value - Pertti - 09-04-2018

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.


RE: pop up window not getting post value - kvanaraj - 09-04-2018

(09-04-2018, 01: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


RE: pop up window not getting post value - InsiteFX - 09-04-2018

Hes' posting json and passing it right to the model, he needs to decode the json first.


RE: pop up window not getting post value - Pertti - 09-04-2018

(09-04-2018, 03: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.


RE: pop up window not getting post value - InsiteFX - 09-04-2018

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.


RE: pop up window not getting post value - Pertti - 09-04-2018

(09-04-2018, 12: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.


RE: pop up window not getting post value - Wouter60 - 09-04-2018

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();