• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Unable to get data ajax using get

#1
I am unable to get any data when I echo json

What I am trying to do is when use selects a image it will upload it and then display files beloing to that question_code

The upload ajax part works fine just can not get the data.

Question Why would the display attachment function not be able to get the data? the when $question_code is correct

The get url out puts on firebug


Code:
http://project.com/question/ask/display_attachments/9471523086



PHP Code:
$('#button-upload input[name="file"]').on('change', function() {
    $.ajax({
        url"<?php echo base_url('question/ask/attachments');?>",
        type'post',
        dataType'json',
        data: new FormData($('#form-ask')[0]),
        cachefalse,
        contentTypefalse,
        processDatafalse,
        success: function(json) {
            // Would not like the second ajax here 
        }
    });

    $.ajax({
        url"<?php echo base_url('question/ask/display_attachments');?>/" + $('#question_code').val(),
        type'get',
        dataType'json',
        success: function(json) {
        }
    });
}); 


Controller Function

PHP Code:
public function display_attachments($question_code) {
    $data = array('attachments' => '');

    $this->db->where('question_code'$question_code);
    $query $this->db->get('attachment');

    if ($query->num_rows() > 0) {

        foreach ($query->result_array() as $result) {
            $data['attachments'][] = array(
                'attachment_id' => $result['attachment_id'],
                'file_name' => $result['file_name']
            );
        }

    }

    echo json_encode($data);

Reply

#2
Code:
$this->output->set_header('Content-Type: application/json; charset=utf-8');
$this->output->set_output(json_encode($data));
Reply

#3
(03-19-2017, 08:11 AM)ivantcholakov Wrote:
Code:
$this->output->set_header('Content-Type: application/json; charset=utf-8');
$this->output->set_output(json_encode($data));

That worked thanks
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.