Welcome Guest, Not a member yet? Register   Sign In
need help in displaying images using codeigniter and ajax
#1

[eluser]doforumda[/eluser]
I am using json to display images using php codeigniter. What I am trying to do is when I click a particular t shirt image then it should display on container div tag. Currently I am getting json code in this format
Code:
[{"rows":[{"shirtid":"8","shirt_thumburl":"shirt_designs\/thumbs\/thumb_blue_four.png","shirturl":"shirt_designs\/blue_four.png"}]}]

So Now how can I get the shirturl from this json data to display that particular image?

here is my code
here is my controller
Code:
class Shirt extends CI_Controller {
    public function index() {
        $this->shirt_thumbs();
    }
    
    public function shirt_thumbs() {
        $data['rows'] = $this->Model_shirt_thumbs->get_thumbs();
        //var_dump($data);
        $this->load->view('view_home',$data);
    }
    
    public function get_tshirt() {
        
        extract($_POST);
        
        $data['rows'] = $this->Model_shirt_thumbs->get_tshirt($id);
        
        $JSON_array = array($data);
        $JSON_response = json_encode($JSON_array);
        header('Contents: type/json');
        echo $JSON_response;
    }
}

here is my .js file
Code:
$(function(){
    $('.thumbs').click(function() {
        var thisid = $(this).attr('id');
        var url = 'http://localhost/shirt_designer/shirt/get_tshirt/';
        $.ajax({
            type: 'POST',
            url: url,
            data: 'id=' + thisid,
            dataType: 'json',
            success: function(result) {
                $('#contents').html(result.shirtid);
            }
        });
    })
});




Theme © iAndrew 2016 - Forum software by © MyBB