Welcome Guest, Not a member yet? Register   Sign In
[Solved] Image Not Display With Javascript
#2

[eluser]riwakawd[/eluser]
Thanks to Tim Brownlaw who helped me on Skype about this issue thought me a lot.

Problem is now fixed.

On view We added

Code:
[removed]
console.log('Jquery is working');
$('select[name="config_template"]').on('change', function () {
  var template_name;
  template_name = encodeURIComponent(this.value);
  $.ajax({
   type: 'POST',
   dataType: 'json',
   url: '<?php echo base_url('admin/setting/template');?>'  + '/',
   data: { config_template: template_name
   },
   complete: function () {
    $('.fa-spin').remove();
   },
   success: function (data) {
    $('.fa-spin').remove();
    $('#template').attr('src', data.image);
   },
   error: function (xhr, ajaxOptions, thrownError) {
    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
   }
  });
})
[removed]

On controller added
Code:
public function template() {
  $this->load->helper('html');
  if (file_exists(FCPATH . 'image/templates/' . $this->configs->get('config_template') . '.png') == FALSE) {
   $img = base_url('image/no_image.png');
   echo json_encode(array('image'=>$img));
  }
  else
  {
   if($this->input->post('config_template') !== FALSE)
   {
    $img = base_url('image/templates/' . $this->input->post('config_template') . '.png');
    echo json_encode(array('image'=>$img));
   }
  }
}


Messages In This Thread
[Solved] Image Not Display With Javascript - by El Forum - 09-14-2014, 05:31 PM
[Solved] Image Not Display With Javascript - by El Forum - 09-15-2014, 06:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB