Welcome Guest, Not a member yet? Register   Sign In
pop up window not getting post value
#1

<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
Reply
#2

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.
Reply
#3

(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
Reply
#4

Hes' posting json and passing it right to the model, he needs to decode the json first.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(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.
Reply
#6

(This post was last modified: 09-04-2018, 12:13 PM by InsiteFX.)

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(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.
Reply
#8

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

Reply




Theme © iAndrew 2016 - Forum software by © MyBB